Skip to content

Instantly share code, notes, and snippets.

@justinfx
Created June 16, 2013 20:26
Show Gist options
  • Select an option

  • Save justinfx/5793291 to your computer and use it in GitHub Desktop.

Select an option

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
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