介绍
QFontDIalog控件是一个常用的字体选择对话框,可以让用户选择所显示文本的字号大小、样式和格式。
方法
方法描述
setWindowTitle()设置对话框标题setWIndowModality()设置窗口模态。取值如下:Qt.NonModal,非模态,可以和程序的其他窗口交互Qt.WindowModel,窗口模态,程序在未处理完当前对话框时,将阻止和对话框的父窗口进行交互Qt.ApplicationModal,应用程序模态,阻止和任何其他窗口进行交互
QDialog的使用
import sys
from PyQt5
.QtCore
import *
from PyQt5
.QtGui
import *
from PyQt5
.QtWidgets
import *
class FontDialogDemo(QWidget
):
def __init__(self
, parent
=None):
super(FontDialogDemo
, self
).__init__
(parent
)
layout
= QVBoxLayout
()
self
.fontButton
= QPushButton
("choose font")
self
.fontButton
.clicked
.connect
(self
.getFont
)
layout
.addWidget
(self
.fontButton
)
self
.fontLineEdit
= QLabel
("Hello,测试字体例子")
layout
.addWidget
(self
.fontLineEdit
)
self
.setLayout
(layout
)
self
.setWindowTitle
("Font Dialog 例子")
def getFont(self
):
font
, ok
= QFontDialog
.getFont
()
if ok
:
self
.fontLineEdit
.setFont
(font
)
if __name__
== '__main__':
app
= QApplication
(sys
.argv
)
demo
= FontDialogDemo
()
demo
.show
()
sys
.exit
(app
.exec_
())
使用展示
后记
字体选择对话框QFontDialog,看看效果吧!
转载请注明原文地址: https://win8.8miu.com/read-1546313.html