PDA

View Full Version : Context Menu in Qt



GAURAV PANT
26th May 2014, 12:37
Hi, i have created a context menu. But when i am hovering mouse over its item, the color of item becomes same as color of background and nothing is displayed.
Please help.

Here is my code:


m_TestViewQTreeView=new QTreeView();

m_TestViewQTreeView->setContextMenuPolicy(Qt::ActionsContextMenu);

QMenu *menu=new QMenu();
menu->setStyleSheet("QMenu{background-color:red}");

QAction *run=new QAction(QIcon(":/Resources/TCstart.png"),"Run",menu);
connect(run,SIGNAL(triggered()),this,SLOT(Run_Clic k()));



m_TestViewQTreeView->addAction(run);

anda_skoa
26th May 2014, 19:45
I don't think you need to create a QMenu when you are using the ActionsContextMenu policy, QWidget will create one and put all actions into it.

Have you tried with a different widget style? Maybe the one you are currently using has a bug?

Cheers,
_