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. CustomContextMenu doesn't always signal my action
QtWS25 Last Chance

CustomContextMenu doesn't always signal my action

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • K Offline
    K Offline
    klsteve
    wrote on last edited by
    #1

    Hi all.

    I have an oddball issue I've been hanging my head against for a few hours, I'm hoping someone can help.

    QT 5.2.0 on OSX.

    I have a form with a QTableWidget containing three rows, each with a custom single column widget spanning the entire width of the table. The table is populated once during application launch and the cells remain inside the table at all times, never destroyed.

    The custom cell (inherits from QWidget) and works well for everything I need, except that my customContextMenu associated with the cell isn't signaling my actions very reliably. For example, only 1 in 8 attempts to select a popup item from the menu results in the action firing, it's usually being ignored.

    For completeness during debugging I added signals to the contextMenu to show when I was hovering over a popup item vs triggering it. In all cases the hover signal is emitted correctly by QMenu - whether I have one or 10 entries in the menu. However, only in some random cases is the trigger signal emitted upon selection, and the action being called.

    Here's a simplified code view:

    void customTableCell::menuHovered(QAction *action)
    {
    qDebug() << "Hovered" << action->text();
    }

    void customTableCell::menuTriggered(QAction *action)
    {
    qDebug() << "Triggered" << action->text();
    }

    /* .h
    private slots:
    void menuHovered(QAction *action);
    void menuTriggered(QAction *action);
    void onMenuDoSomething(void);
    */
    void customTableCell::onMenuDoSomething(void)
    {
    qDebug() << "onMenuDoSomething()";
    }

    here's my contextMenu:

    void customTableCell::on_customContextMenuRequested(const QPoint &pos)
    {
    Q_UNUSED(pos);

    QMenu *contextMenu = new QMenu( this );
    Q_CHECK_PTR ( contextMenu );
    
    contextMenu->addAction("Do Something", this , SLOT(onMenuDoSomething(void)));
    
    connect(contextMenu, SIGNAL(hovered(QAction *)), this, SLOT(menuHovered(QAction *)));
    connect(contextMenu, SIGNAL(triggered(QAction *)), this, SLOT(menuTriggered(QAction *)));
    
    contextMenu->popup( QCursor::pos() );
    contextMenu->exec&#40; &#41;;
    
    delete contextMenu;
    contextMenu = 0;
    

    }

    It doesn't matter whether I have a single entry in the menu, or 10 items, QT is randomly choosing to trigger my actions or not.

    In every other case where I've used customContextMenus (on different widgets) they work 100% reliably, this is the first time I've attached a menu to an object derived from QWidget and seen this behavior.

    Follow-up no shown here:

    ->exec() returns the QAaction object correctly only when the Action has truly fired. If the action never fired, even though it was selected, ->exec() returns null.

    Additionally, placing signals on the QAction itself (triggered() ) only emits when the solution works, 1 in 8 or so times.

    Feels like a bug in QMenu but I'm not sure how to work around this.

    Any ideas?

    Thanks,

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

      Hi and welcome to devnet,

      Can you try with 5.2.1 to see if it still behaves incorrectly ?

      If so, you should consider reporting it on "the bug report system":http://bugreports.qt-project.org .

      Please provide a minimal compilable sample program that reproduce the behavior

      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
      • K Offline
        K Offline
        klsteve
        wrote on last edited by
        #3

        Thanks for the feedback.

        Upgrading to 5.2.1 didn't help.

        Interesting though, the same code works perfectly with 5.2.1 on Linux. 100% reliable.

        Mac bug I think.

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

          Sounds like it indeed, please open a report (if none already exists) with a minimal compilable example.

          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