PDA

View Full Version : Right click list - some advice ?



aurelius
26th January 2009, 20:43
I want to create a right click list. I couldn't find any appropriate class doing directly that, so I started creating one. I made a custom class inheriting QWidget, which has a QList of QLabel in a QGridLayout, so they end up one under the other. I adjusted it generally to look like a right click list. The problem is, I want to make it close when there is mouse click event not in the widget's area. So, I wanted to ask, if there is some function for global mouse click event, which intercepts the mouse click event of a specific object, and which will then allow the program to continue as normal, calling the individual's object mouse click event ?

Also, in QWidget there is no mouse hover event. Is there any way, besides doing it the hard way, to know over which labels the cursor is ?

caduel
26th January 2009, 21:08
just curious: what is a right click list?

jpn
26th January 2009, 21:15
I suppose "right click list" means QWidget::contextMenuEvent() + QMenu. :)

faldzip
26th January 2009, 21:38
So if your "right click list" is a context menu (also known as "popup menu") you can do something like this:


void SomeWidget::contextMenuEvent(QContextMenuEvent* e)
{
QMenu* m = new QMenu(this);
m->addAction(tr("parabola"));
m->addAction(tr("karoseria"));
m->addAction(tr("kulomiot"));

m->move(mapToGlobal(e->pos()));
m->show();
}

Where SomeWidget is a widget where you want your context menu to appear in. In this example you will have 3 element menu (list).

aurelius
26th January 2009, 21:41
just curious: what is a right click list?

Yeah, you 're right, it wasn't such a good description, I am sorry.

@all other:

thanx, I was hoping that there is sth already implemented for this kind of things.

I will look them.

Thanx :)

caduel
27th January 2009, 07:04
for simple cases you might just add the actions to the widget and set QWidget::setContextMenuPolicy() to Qt::ActionsContextMenu