[Qt-interest] Menu Bar - Drawing back ground

Lars Amsel lars.amsel at signalion.com
Wed Jul 1 11:38:24 CEST 2009


Santhosh,

Santhosh Y wrote:
> It works but the paintEvent of QMenuBar is over-riding background. So 
> half the portion will be seen with the style sheet set background and 
> the other
> half i.e. with menu back ground is default.
> 
> My issue is setting the style sheet back ground to the entire menu bar.

There is no need to override the paint method. You have to make the items 
transparent in the stylesheet:

QMenuBar {
   background-image: url(:/res/menu_bg.png);
}
QMenuBar::item {
   background-color: transparent;
}

You may also set the selected/pressed/ states like this

QMenuBar::item:selected {
   background-color: red;
);


Lars



More information about the Qt-interest-old mailing list