The QtGui.QFontDialog is a dialog widget for selecting a font.

#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we select a font name
and change the font of a label. author: Jan Bodnar
website: zetcode.com
last edited: October 2011
""" import sys
from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): vbox = QtGui.QVBoxLayout() btn = QtGui.QPushButton('Dialog', self)
btn.setSizePolicy(QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed) btn.move(20, 20) vbox.addWidget(btn) btn.clicked.connect(self.showDialog) self.lbl = QtGui.QLabel('Knowledge only matters', self)
self.lbl.move(130, 20) vbox.addWidget(self.lbl)
self.setLayout(vbox) self.setGeometry(300, 300, 250, 180)
self.setWindowTitle('Font dialog')
self.show() def showDialog(self): font, ok = QtGui.QFontDialog.getFont()
if ok:
self.lbl.setFont(font) def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()

In our example, we have a button and a label. With QtGui.QFontDialog, we change the font of the label.

font, ok = QtGui.QFontDialog.getFont()

Here we pop up the font dialog. The getFont() method returns the font name and the ok parameter. It is equal to True if the user clicked OK; otherwise it is False.

if ok:
self.label.setFont(font)

If we clicked ok, the font of the label would be changed.

QtGui.QFontDialog的更多相关文章

  1. PyQt4字体对话框QFontDialog

    字体对话框时用来显示字体的对话框部件. #!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui, Qt ...

  2. PyQt4入门学习笔记(五)

    PyQt4里的对话框 对话框是大多数GUI应用中不可分割的一部分.一个对话框是两者或多者的会话.在GUI内,对话框是应用向人说话的方式.一个对话框可以用来输入数据,修改数据,改变应用设置等等. QtG ...

  3. Qt: 内建对话框(各种对话框都有了,且用到了qobject_cast解析sender的技术)

    #include "BuiltinDialog.h" #include <QtGui/QTextEdit> #include <QtGui/QPushButton ...

  4. Python -- Gui编程 -- Qt库的使用 -- 菜单与对话框

    1.菜单 import sys from PyQt4 import QtCore, QtGui class MyWindow(QtGui.QMainWindow): def __init__(self ...

  5. QDialog:输入对话框、颜色对话框、字体对话框、文件对话框

    # _*_ coding:utf-8 _*_ import sys from PyQt4 import QtCore,QtGui class Example(QtGui.QWidget): def _ ...

  6. ZetCode PyQt4 tutorial Dialogs

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  7. PyQt4 颜色选择,字体选择代码

    # -*- coding: utf-8 -*- """ ------------------------------------------------- File Na ...

  8. 读Pyqt4教程,带你入门Pyqt4 _005

    对话框窗体或对话框是现代GUI应用不可或缺的一部分.dialog定义为两个或多个人之间的交谈.在计算机程序中dialog是一个窗体,用来和程序“交谈”.对话框用来输入数据.修改数据.改变程序设置等等. ...

  9. 六、pyqt5对话框——QInputDialog、QColorDialog、QFontDialog、QMessageBox、QFileDialog

    目录:  一.对话框综合示例 二.QDialog 三.QInputDialog 四.QMessageDialog 五.QFileDialog pyqt5的对话框有多种类型,比如输入对话框(QInput ...

随机推荐

  1. 「ZJOI2018」历史

    「ZJOI2018」历史 前置知识 \(\text{LCT}\) 维护子树信息,考虑辅助树上一个节点的子树信息只是其代表的这一段链的信息,设 \(S(u)\) 为节点 \(u\) 的子树信息,那么在辅 ...

  2. 【最小表示法】BZOJ2176-Strange string(unsigned char!!!)

    [题目大意] 给定一个字符串S = {S1, S2, S3 … Sn}, 如果在串SS中, 子串T(|T| = n)为所有长度为n的SS的字串中最小的(字符串的比较), 则称T为”奇怪的字串”. 你的 ...

  3. VIM选项配置说明

    选项配置说明 选项书写格式 选项说明 :se[t] 显示所有被改动的选项 :se[t] all 显示所有非 termcap 选项 :se[t] termcap 显示所有 termcap 选项 :se[ ...

  4. 线性DP POJ 1159 Palindrome

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 59101   Accepted: 20532 Desc ...

  5. 2015 UESTC 数据结构专题H题 秋实大哥打游戏 带权并查集

    秋实大哥打游戏 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...

  6. 解决因为google cdn无法访问导致无法打开stackoverflow等网站的方法

    许多网站使用了Google的CDN来加速Jquery之类的库来加速网站访问,但由于方校长发福利的原因,导致这些网站很容易出现无法加载"ajax.googleapis.com"而出现 ...

  7. MariaDB Audit Plugin 1.2

    下载地址:https://downloads.mariadb.com/enterprise/bbfz-atd2/mariadb-audit-plugin/server_audit-1.2.0.tar. ...

  8. visual studio xcopy /exclude测试

    http://files.cnblogs.com/files/zfanlong1314/exclude%E6%B5%8B%E8%AF%95.zipxcopy 提供了 /EXCLUDE: 参数用于在复制 ...

  9. hibernate将connection放进threadlocal里实现数据库连接池

    Why ThreadLocal? 无论如何,要编写一个多线程安全(Thread-safe)的程序是困难的,为了让线程共享资源,必须小心地对共享资源进行同步,同步带来一定的效能延迟,而另一方面,在处理同 ...

  10. Unity3D开发之查找面板上某个脚本(包含Missing)

    有时候我们须要知道某个脚本在场景上面哪里用到,或者那个脚本被删除了但又没有把相关游戏场景的关联东西删掉,那样我们就要一个脚本来查找一下了: PS:以下两个脚本都要放到assets/Editor以下哦. ...