python - qt stylesheet not working -
so writing small program,here code:
import sys pyqt5.qt import qapplication pyqt5 import qtwidgets class cmywidget(qtwidgets.qwidget): def __init__(self,p = none): super(cmywidget,self).__init__(p) if __name__ == "__main__": app = qapplication(sys.argv) #w = qtwidgets.qwidget() #this ok #1 w = cmywidget() #2 label = qtwidgets.qlabel(w) label.settext("12345") btn = qtwidgets.qpushbutton(w) btn.settext("x") hlayout = qtwidgets.qhboxlayout(w) hlayout.addwidget(label) hlayout.addwidget(btn) w.setstylesheet("border:none;"\ "border-bottom:5px solid rgb(255,0,0)") w.show() sys.exit(app.exec_())
the problem if use #1
,then ok,all widgets's bottom border drawed;but if change #2
,only child widget draw bottom border,the cmywidget
won't draw bottom border,am doing wrong here?
there problems stylesheets when try use in derived classes. solve problem, try use this:
w = cmywidget() w.setattribute(qtcore.qt.wa_styledbackground)
in code qtcore.qt.wa_styledbackground
means widget should drawn using styled background.
Comments
Post a Comment