PDA

View Full Version : Styling QMenubar???



anupamgee
29th April 2009, 08:21
hi all,
I want to style a Qmenubar. i want to make it transparent i.e it should take the background color of widget in which it is formed.i am using stylesheet for it .but it is not working..
i used the following code:


TabWindow::TabWindow(QWidget *parent): QWidget(parent)
{
menubar=new QMenuBar(this);
fileMenu=new QMenu("File",this);
actionMenu=new QMenu("Actions",this);
menubar->addMenu(fileMenu);
menubar->addMenu(actionMenu);
menubar->setStyleSheet("background-color: transparent");
}

What to do??

Lykurg
29th April 2009, 08:53
Put your menu bar in the widget layout and it should work. Note that QWidget has by default no space for a QMenuBar like QMainWindow has it!

anupamgee
29th April 2009, 09:18
thnx for reply,
I tried this but it does nt work...........
I used this way


Widget::Widget(QWidget *parent): QWidget(parent)
{ menubar=new QMenuBar(this);
fileMenu=new QMenu("File",this);
menubar->setGeometry(10,10,40,20);
actionMenu=new QMenu("Actions",this);
menubar->addMenu(fileMenu);
menubar->addMenu(actionMenu);
menubar->setStyleSheet("background-color: red);");
}


But widget is not showing menubar
How to do??

Lykurg
29th April 2009, 09:28
You have a typo! Skip the ")".


menubar->setStyleSheet("background-color: red;");

anupamgee
29th April 2009, 09:43
I corrected that but still not showing the menubar
if i skip the line menubar->setStyleSheet("background-color: red;");
it shows the normal qmenubar.
what is the problem in setting stylesheet

Lykurg
29th April 2009, 10:01
It's because you have not put the menubar in a layout! If you don't want to do so call
menubar->adjustSize(); then the menu bar is shown. (Skip your geometry line.)