首页 > 其他分享 >PyQT5之QFontDialog

PyQT5之QFontDialog

时间:2024-06-13 17:37:24浏览次数:19  
标签:__ layout fonButton self PyQT5 PyQt5 QFontDialog import


import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *


class FontDialogdemo(QWidget):
    def __init__(self, parent=None):
        super(FontDialogdemo, self).__init__(parent)
        self.resize(500, 300)
        # 垂直布局
        layout = QVBoxLayout()

        # 创建按钮,绑定自定义槽函数,添加到布局中
        self.fonButton = QPushButton('Choose Font')
        self.fonButton.clicked.connect(self.getFont)
        layout.addWidget(self.fonButton)

        # 创建标签,添加dao到布局中
        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_())


标签:__,layout,fonButton,self,PyQT5,PyQt5,QFontDialog,import
From: https://www.cnblogs.com/jackchen28/p/18246360

相关文章

  • PyQT5之QDialog
    importsysfromPyQt5.QtCoreimport*fromPyQt5.QtGuiimport*fromPyQt5.QtWidgetsimport*classQDialogDemo(QMainWindow):def__init__(self):super().__init__()self.initUI()definitUI(self):self.setWindowTitle(�......
  • PyQT5之多页面切换
    fromPyQt5.QtWidgetsimportQApplication,QWidget,QStackedLayout,QVBoxLayoutfromPyQt5.QtWidgetsimportQPushButton,QComboBox,QSizePolicyimportsysif__name__=='__main__':app=QApplication(sys.argv)my_widget=QWidget()my_w......
  • 【Python】成功解决ModuleNotFoundError: No module named ‘PyQt5‘
    【Python】成功解决ModuleNotFoundError:Nomodulenamed‘PyQt5’ 下滑即可查看博客内容......
  • PyQT5之QSS基础/子控件选择器
    fromPyQt5.QtWidgetsimport*importsysclassBasicQCSS(QWidget):def__init__(self):super().__init__()self.setWindowTitle("QSS样式/子控件选择器")btn1=QPushButton(self)btn1.setText("按钮1")b......
  • PyQT5窗口样式设置
    importsysfromPyQt5.QtCoreimport*fromPyQt5.QtGuiimport*fromPyQt5.QtWidgetsimport*classWindowPattern(QMainWindow):def__init__(self,*args,**kwargs):super().__init__(*args,**kwargs)self.resize(500,300)self......
  • PyQT5之设置窗口控件风格
    设置窗口控件风格QApplication.setStyle(...)窗口可以显示三种风格:['windowsvista','Windows','Fusion']importsysfromPyQt5.QtCoreimport*fromPyQt5.QtGuiimport*fromPyQt5.QtWidgetsimport*#print(QStyleFactory.keys())classWindow......
  • PyQT5之多窗口交互
    方法一:不适用信号与槽MultiWin.py文件"""多窗口交互--不适用信号与槽"""importsysfromPyQt5.QtCoreimport*fromPyQt5.QtGuiimport*fromPyQt5.QtWidgetsimport*fromDateDialogimportDateDialogclassMultiWindow1(QWidget):def__init__......
  • PyQT5之为槽函数传递参数
    方法一:lambda表达式传递参数fromPyQt5.QtCoreimport*fromPyQt5importQtCorefromPyQt5.QtWidgetsimport*importsysclassLambdaSlotArg(QMainWindow):def__init__(self):super().__init__()self.setWindowTitle("使用Lambda表达式为槽函......
  • PyQT5信号与槽的连接
    方法一:fromPyQt5.QtCoreimport*fromPyQt5.QtWidgetsimport*importsysclassAutoSignalSlot(QWidget):def__init__(self):super().__init__()self.setWindowTitle("信号与槽自动连接")self.resize(300,100)self.okB......
  • PyQT5信号刷新时间
    importtimefromPyQt5.QtCoreimport*fromPyQt5.QtWidgetsimport*importsysclassBackendThread(QThread):update_date=pyqtSignal(str)defrun(self):whileTrue:data=QDateTime.currentDateTime()currentTim......