QtGui.QColorDialog
2024-08-26 03:54:53
he QtGui.QColorDialog
provides a dialog widget for selecting colour values.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we select a colour value
from the QtGui.QColorDialog and change the background
colour of a QtGui.QFrame widget. 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): col = QtGui.QColor(0, 0, 0) self.btn = QtGui.QPushButton('Dialog', self)
self.btn.move(20, 20) self.btn.clicked.connect(self.showDialog) self.frm = QtGui.QFrame(self)
self.frm.setStyleSheet("QWidget { background-color: %s }"
% col.name())
self.frm.setGeometry(130, 22, 100, 100) self.setGeometry(300, 300, 250, 180)
self.setWindowTitle('Color dialog')
self.show() def showDialog(self): col = QtGui.QColorDialog.getColor() if col.isValid():
self.frm.setStyleSheet("QWidget { background-color: %s }"
% col.name()) def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
The application example shows a push button and a QtGui.QFrame
. The widget background is set to black colour. Using the QtGui.QColorDialog
, we can change its background.
col = QtGui.QColor(0, 0, 0)
This is an initial colour of the QtGui.QFrame
background.
col = QtGui.QColorDialog.getColor()
This line will pop up the QtGui.QColorDialog
.
if col.isValid():
self.frm.setStyleSheet("QWidget { background-color: %s }"
% col.name())
We check if the colour is valid. If we click on the Cancel button, no valid colour is returned. If the colour is valid, we change the background colour using style sheets.
Figure: Color dialog
最新文章
- C#开发微信门户及应用(39)--使用微信JSSDK实现签到的功能
- JVM内存管理------垃圾搜集器精解(让你在垃圾搜集器的世界里耍的游刃有余)
- screenshot of termbox cjk commit
- 遇到一位ITer,一位出租车司机,必看。
- HTML学习体会
- linux安全加固(2)
- angular 模板 小例子
- Gravitational Teleport 是一个先进的 SSH 服务器,基于 Golang SSH 构建,完全兼容 OpenSSH
- 推荐 15 个 Angular.js 应用扩展指令(参考应用)
- DeepID人脸识别算法之三代(转)
- Android 查看内存
- c++之 scanf 接收用户输入内容
- SSM增删改查
- asp+SqlServer2008开发【第四集:windows server 2008 r2的操作记录】
- mysql学习笔记--数据操作
- Block(一)基础-b
- 把AspDotNetCoreMvc程序运行在Docker上-part4:实现负载均衡
- 【六】注入框架RoboGuice使用:(Singletons And ContextSingletons)
- 吴恩达 Deep learning 第一周 深度学习概论
- java-length 、length()、size()的区别