qt - Same style for QPushButton and QToolButton during mouse-over -


is possible make qpushbutton , qtoolbutton identical during mouse-over, i.e. , feel hover events?

i don't use custom stylesheets, there global application setting:

qtgui.qapplication.setstyle("plastique") 

i'm looking "propagate" current (system-default) mouse-over-stylesheet of qpushbutton qtoolbutton. default, qpushbutton highlighted during mouse-over, while qtoolbutton nothing @ all.

environment: qt 4.8.6, running on linux centos 6 , windows 7

taking nicolas answer starting point, created own css style sheet:

qpushbutton,qtoolbutton {    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #fdfbf7, stop: 1 #cfccc7);   border-width: 1px;   border-color: #8f8f91;   border-style: solid;   border-radius: 3px;   padding: 4px;   padding-left: 5px;   padding-right: 5px; }  qtoolbutton[popupmode="1"] {    padding-right: 18px; }  qtoolbutton::menu-button {    border-width: 1px;   border-color: #8f8f91;   border-style: solid;   border-top-right-radius: 3px;   border-bottom-right-radius: 3px;   /* 16px width + 2 * 1px border = 18px allocated above */   width: 16px; }  qpushbutton:hover,qtoolbutton:hover {    border-top-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #b2afaa, stop: 0.5 #4847a1, stop: 1 #7e7cb6);   border-radius: 1px;   border-top-width: 3px;   border-bottom-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #7e7cb6, stop: 0.5 #4847a1, stop: 1 #b2afaa);   border-bottom-width: 3px;   background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e4e0e1, stop: 1 #cfcbcd); }  qpushbutton:pressed,qtoolbutton:pressed {    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #cfcbcd, stop: 1 #e4e0e1);   border-width: 1px;   border-color: #8f8f91; }  qpushbutton:focus,qtoolbutton:focus {    outline: none; } 

to apply style, used following pyqt code snippet:

cssfile = os.path.join(self.installdir, "etc", "buttons.css") open(cssfile, "r") fh:     cssstylesheet = "".join(fh.readlines())      in range(self.verticallayout.count()):         widget = self.verticallayout.itemat(i).widget()         if isinstance(widget, qtgui.qpushbutton) or isinstance(widget, qtgui.qtoolbutton):             widget.setstylesheet(cssstylesheet)         # make tool- , pushbutton same height...         if isinstance(widget, qtgui.qtoolbutton):             widget.setmaximumheight(self.firstpushbutton.sizehint().height()) 

the resulting , feel identical default "plastique" style, if application background color set "#ede9e3".

at first, applied style sheet tool- , pushbuttons (i.e. system default). after this, buttons in dialogs lost there default width. decided apply style buttons inside of vertical layout, contains involved buttons.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -