python - How to set PyQT4 Stylesheet for Matplotlib widget (navBar/canvas)? -


i have qmainwindow app consisting of menu bar, splitter in central widget, , status bar. on left side of splitter widget containing controls (list, combo, , button) , on right widget containing layout of matplotlib canvas, , navigationtoolbar.

i able use qt stylesheets set various background colors of ... except matplotlib side. attempted use following has no effect. tried setting navbar , canvas stylesheets directly ... again didn't work:

self.mplfig.setstylesheet(".qwidget {background-color:   #0ff}") 

basically trying turn background color of navtoolbar , border around canvas match else (currently cyan shows easy) ... appreciated. full code & sample image below:

import sys pyqt4 import qtgui, qtcore import matplotlib matplotlib.use("qt4agg") matplotlib.backends.backend_qt4agg import figurecanvasqtagg figurecanvas matplotlib.backends.backend_qt4agg import navigationtoolbar2qt navigationtoolbar matplotlib.figure import figure  class testgui(qtgui.qmainwindow):     def __init__(self, parent=none):         super(testgui, self).__init__(parent)         self.buildlayout()         self.buildmenus()                 self.menubar()         self.statusbar()          ## style sheets         self.splitter.setstylesheet("qsplitter::handle:horizontal {background-color:   #ccc}")                     self.controlwidget.setstylesheet(".qwidget {background-color:   #0ff}")           menustyle = """.qmenubar {background-color:   #0ff}             qmenubar::item {background: transparent}              qmenubar::item:selected {background: #8ff}"""         self.statusbar().setstylesheet(".qstatusbar {background-color:   #0ff}")         self.menubar().setstylesheet(menustyle)         # .....this doesn"t work !! .....         self.mplfig.setstylesheet(".qwidget {background-color:   #0ff}")       def buildlayout(self):         self.controlwidget = qtgui.qwidget(self)          self.plotlist  = qtgui.qlistwidget(self)         self.combo  = qtgui.qcombobox(self)         self.button = qtgui.qpushbutton('plot')                 self.combo.additems(\['1','2','3','4'\])          layout = qtgui.qvboxlayout()         layout.addwidget(self.plotlist)         layout.addwidget(self.combo)         layout.addwidget(self.button)         self.controlwidget.setlayout(layout)         self.mplfig  = mplgrapher()         self.splitter = qtgui.qsplitter(qtcore.qt.horizontal)         self.splitter.addwidget(self.controlwidget)          self.splitter.addwidget(self.mplfig)          self.setcentralwidget(self.splitter)         qtgui.qapplication.setstyle(qtgui.qstylefactory.create('plastique'))     def buildmenus(self):         openfile = qtgui.qaction('open', self)         self.filemenu = self.menubar().addmenu('&file')         self.filemenu.addaction(openfile)  class mplgrapher(qtgui.qwidget):     def __init__(self,parent=none):         super(mplgrapher, self).__init__(parent)         self.initfigure()      def initfigure(self):            self.figure = figure()                 self.canvas = figurecanvas(self.figure)         self.navbar = navigationtoolbar(self.canvas, self)          self.figure.add_subplot(1,1,1)         self.layout = qtgui.qvboxlayout()         self.layout.addwidget(self.navbar)         self.layout.addwidget(self.canvas)         self.setlayout(self.layout)  if __name__ == '__main__':     app = qtgui.qapplication(sys.argv)     main = testgui()     main.show()     sys.exit(app.exec_()) 

sample gui

i think may have solution tips maxwell grady.

i changed following 2 lines:

self.mplfig.setstylesheet("qwidget {background-color:   #0ff}") 

note lack of "." before qwidget and

class mplgrapher(qtgui.qgroupbox): 

picture of gui after changes. can set style properties ... time make less ugly.

sample colored in borders.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -