Created
September 4, 2015 09:36
-
-
Save saleph/f443ba03318cf0de7ee9 to your computer and use it in GitHub Desktop.
[qt6] qframe's color setting with qcolordialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtWidgets import (QWidget, QPushButton, QFrame, | |
QColorDialog, QApplication) | |
from PyQt5.QtGui import QColor | |
class Example(QWidget): | |
def __init__(self): | |
super().__init__() | |
self.init_ui() | |
def init_ui(self): | |
col = QColor(0, 0, 0) | |
self.btn = QPushButton('Dialog', self) | |
self.btn.move(20, 20) | |
self.btn.clicked.connect(self.show_dialog) | |
self.frm = QFrame(self) | |
self.frm.setStyleSheet("QWidget { background-color: %s }" % col.name()) | |
self.frm.setGeometry(130, 22, 100, 100) | |
self.setGeometry(300, 300, 250, 100) | |
self.setWindowTitle('Color dialog') | |
self.show() | |
def show_dialog(self): | |
col = QColorDialog.getColor() | |
if col.isValid(): | |
self.frm.setStyleSheet("QWidget { background-color: %s }" % col.name()) | |
if __name__ == "__main__": | |
app = QApplication(sys.argv) | |
ex = Example() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment