Created
June 16, 2013 20:26
-
-
Save justinfx/5793291 to your computer and use it in GitHub Desktop.
Example of having QColorDialog remember the last color selection
Corrected from: http://pastebin.com/L9ge14k0
This file contains hidden or 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
| from PyQt4 import QtCore, QtGui | |
| class ColorBox(QtGui.QFrame): | |
| def __init__(self,parent=None): | |
| super(ColorBox,self).__init__(parent) | |
| self.bgColor = QtCore.Qt.white | |
| self.setFixedHeight(20) | |
| self.setFrameStyle(1) | |
| self.setStyleSheet("QWidget { border-color: rgba(0,0,0,0)}") | |
| def mousePressEvent(self, e): | |
| if e.buttons() == QtCore.Qt.LeftButton: | |
| col = QtGui.QColorDialog.getColor(self.bgColor, self) | |
| if col.isValid(): | |
| rgb = (col.red(), col.green(), col.blue()) | |
| self.setStyleSheet("QWidget { background-color: rgb(%d,%d,%d) }" % rgb) | |
| self.bgColor = col | |
| if __name__ == "__main__": | |
| app = QtGui.QApplication([]) | |
| c = ColorBox() | |
| c.show() | |
| app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment