Context menu long left click on QGraphicsTextItem
Hello,
I try to have a context menu in Qt if we do a long press on a QGraphicsItemGroup. I have try basic thing like this:
my .h:
Code:
{
Q_OBJECT
public:
~myclass();
public slots:
private:
Ui::myclassClass ui;
my cpp:
Code:
{
if (event)
{
menu
->addAction
(new QAction("Action 1",
this));
menu
->addAction
(new QAction("Action 2",
this));
menu
->addAction
(new QAction("Action 3",
this));
menu->exec(event->globalPos());
}
}
It's work, but only with right click. And how to have this only on a QGraphicsItemGroup with a long left click ?
Re: Context menu long left click on QGraphicsTextItem
You can detect the pressEvent and then use a timer to measure the hold. If the timer fires before you detect a release you have a long-press. If the release happens before, you stop the timer.
For a QGraphicsObject subclass you could also try QGraphicsObject::grabGesture()
Cheers,
_