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:
{
Q_OBJECT
public:
~myclass();
public slots:
private:
Ui::myclassClass ui;
class myclass: public QMainWindow
{
Q_OBJECT
public:
myclass(QWidget *parent = 0);
~myclass();
public slots:
void contextMenuEvent(QContextMenuEvent *event);
private:
Ui::myclassClass ui;
To copy to clipboard, switch view to plain text mode
my cpp:
{
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());
}
}
void myclass::contextMenuEvent(QContextMenuEvent *event)
{
if (event)
{
QMenu *menu = new QMenu;
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());
}
}
To copy to clipboard, switch view to plain text mode
It's work, but only with right click. And how to have this only on a QGraphicsItemGroup with a long left click ?
Bookmarks