Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Context menu long left click on QGraphicsTextItem

Context menu long left click on QGraphicsTextItem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    flavien317
    wrote on last edited by
    #1

    Hello,
    I try to have a context menu in Qt if we do a long press on left click on a QGraphicsItemGroup. I have try basic thing like this:
    my .h:
    @
    class myclass: public QMainWindow
    {
    Q_OBJECT
    public:
    myclass(QWidget *parent = 0);
    ~myclass();

    public slots:
    void contextMenuEvent(QContextMenuEvent *event);
     
    private:
    Ui::myclassClass ui;@
    

    my cpp:
    @ 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());
    }
    }@

    It's work, but only with right click. And how to have this only on a QGraphicsItemGroup with a long left click ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      One way would be to implement mousePressEvent and mouseReleaseEvent and use a QTimer for the delay.

      Also, note that you are having a memory leak here since you never delete menu.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved