PDA

View Full Version : how to change background color of QMenu??



anupamgee
28th April 2009, 13:27
hi all,
i want to change the background color of Qmenu.
i tried the following code:


TabWindow::TabWindow(QWidget *parent) : QWidget(parent)
{
QMenu *menu=new QMenu(this);
onlineAct = new QAction(tr("Online"), this);
busyAct = new QAction(tr("Busy"), this);
menu->addAction(onlineAct);
menu->addAction(busyAct);
connect(onlineAct,SIGNAL(triggered()),this,SLOT(on line()));
connect(busyAct,SIGNAL(triggered()),this,SLOT(busy ()));
menu->setAutoFillBackground(true);
QPalette palette=menu->palette();
palette.setColor(QPalette::Window, Qt::blue);
menu->setPalette(palette);
}

but the color is not changing.It is showing white background color.
what to do??

spirit
28th April 2009, 13:29
have a look at this (http://doc.trolltech.com/4.5/stylesheet-examples.html#customizing-qmenu) examples.

anupamgee
28th April 2009, 13:37
thnx for reply,
i am new in qt.Can you plz tell with an example how to use that ?

spirit
28th April 2009, 13:41
you can set style sheet using this method QWidget::setStyleSheet.
so, in you case you should write something like this


TabWindow::TabWindow(QWidget *parent) : QWidget(parent)
{
QMenu *menu=new QMenu(this);
menu->setStyleSheet(...);
...
}