python - How do I get the or set the native highlight color of a QWidget? -


i have created custom qwidgetaction offer 2 menu options; text , delete icon.

i can control highlight color through :hover in stylesheet, don't want hard-code colors. want use native colors current environment.

how query default value palette?

i have found qpalette.setcolor(), hoping find similar qpalette.getcolor() not exist.

here's example code might explain how want apply highlight.

class preferenceaction(qtgui.qwidgetaction):     def __init__(self,  preffile, parentmenu, *args, **kw):         qtgui.qwidgetaction.__init__(self, parentmenu, *args, **kw)          self.parentmenu = parentmenu         self.preffile = preffile         self.prefname = os.path.basename(preffile)[:-5].replace("_",' ')          mywidget = qtgui.qwidget()         mylayout = qtgui.qhboxlayout()         mylayout.setspacing( 0 )         mylayout.setcontentsmargins( 0, 0, 0, 0 )         mywidget.setlayout(mylayout)         mylabel = extendedqlabel(self.prefname)         myicon = extendedqlabel()         myicon.setpixmap(qtgui.qpixmap(trash_icon))         mylayout.addwidget(mylabel, stretch=1)         mylayout.addwidget(myicon, stretch=0)         mywidget.setstylesheet("qwidget:hover { background:#3399ff; color: white;} qwidget { padding: 4px;}")          self.connect(mylabel, qtcore.signal('clicked()'), self.loadpreference)         self.connect(myicon, qtcore.signal('clicked()'), self.deletepreference)          self.setdefaultwidget(mywidget)      def loadpreference(self):         print "loading preference %s" % self.preffile         self.parentmenu.hide()      def deletepreference(self):         print "deleting preference %s" % self.preffile         self.parentmenu.hide()  class extendedqlabel(qtgui.qlabel):      def __init(self, parent):         qtgui.qlabel.__init__(self, parent)      def mousereleaseevent(self, ev):         self.emit(qtcore.signal('clicked()')) 


update: have found option. it's not super pretty works.

defaulthlbackground = "#%02x%02x%02x" % mywidget.palette().highlight().color().getrgb()[:3] defaulthltext = "#%02x%02x%02x" % mywidget.palette().highlightedtext ().color().getrgb()[:3]  mywidget.setstylesheet("qwidget:hover { background:%s; color: %s;} qwidget { padding: 4px;}" % (defaulthlbackground,defaulthltext)) 

the "name" of color used directly in css style this:

yourwidget.palette().highlight().color().name() 

you've found out there's no getcolor(), color(). api conventions in qt different common in java , python.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -