• PyQt4 颜色选择,字体选择代码


    # -*- coding: utf-8 -*-
    """
    -------------------------------------------------
       File Name:     buttonTest
       Description :
       Author :       神秘藏宝室
       date:          2017-09-30
    -------------------------------------------------
       Change Activity:
                       2017-09-30:
    -------------------------------------------------
    """
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')
    from PyQt4 import QtGui,QtCore
    
    class ColorChange(QtGui.QWidget):
        def __init__(self):
            QtGui.QWidget.__init__(self)
            self.setGeometry(300, 300, 350, 180)
            self.setWindowTitle(u'调色盘')
    
            self.color = QtGui.QColor(255,255,255)
            self.button = QtGui.QPushButton(u'选择颜色',self)
            self.button.setFocusPolicy(QtCore.Qt.NoFocus)
            self.button.move(20,20)
            self.connect(self.button,QtCore.SIGNAL('clicked()'),self.showDialog)
            self.setFocus()
    
            self.widget = QtGui.QWidget(self)
            self.widget.setStyleSheet('QWidget{background-color:%s}'% self.color.name())
            self.widget.setGeometry(130,22,100,100)
    
        def showDialog(self):
            col= QtGui.QColorDialog.getColor()
            if col.isValid():
                self.widget.setStyleSheet('QWidget{background-color:%s}' % col.name())
    
    class Font(QtGui.QWidget):
        def __init__(self):
            QtGui.QWidget.__init__(self)
            self.setGeometry(300, 300, 350, 180)
            self.setWindowTitle(u'字体选择')
    
            hbox = QtGui.QHBoxLayout()
            self.button = QtGui.QPushButton(u'选择字体',self)
            self.button.setFocusPolicy(QtCore.Qt.NoFocus)
            self.button.move(20,20)
            hbox.addWidget(self.button)
            self.connect(self.button,QtCore.SIGNAL('clicked()'),self.showDialog)
    
            self.label = QtGui.QLabel(u'测试颜色测试颜色测试颜色测试颜色',self)
            self.label.move(130,20)
            hbox.addWidget(self.label,1)
            self.setLayout(hbox)
    
        def showDialog(self):
            font,ok=QtGui.QFontDialog.getFont()
            if ok:
                self.label.setFont(font)
    
    
    
    app = QtGui.QApplication(sys.argv)
    test = Font()
    test.show()
    sys.exit(app.exec_())
    
  • 相关阅读:
    896. 单调数列
    819. 最常见的单词
    collections.Counter()
    257. 二叉树的所有路径
    万里长征,始于足下——菜鸟程序员的学习总结(三)
    Ogre启动过程&原理
    Ogre导入模型
    四元数
    Ogre3D嵌入Qt框架
    如何搭建本地SVN服务
  • 原文地址:https://www.cnblogs.com/Mysterious/p/7616441.html
Copyright © 2020-2023  润新知