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. Clearing a QMenu while open toggles visibility

Clearing a QMenu while open toggles visibility

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.4k Views 2 Watching
  • 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.
  • P Offline
    P Offline
    pino
    wrote on last edited by
    #1

    I found a weird behavior with context menus. When I clear it, it toggles visibility.

    Create a Qt desktop app and a window with a tree view. Insert the following:

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
    }
    
    void MainWindow::on_treeView_customContextMenuRequested(const QPoint &pos)
    {
        QMenu *m = new QMenu();
        m->addAction("foo");
        QTimer t;
        connect(&t, &QTimer::timeout, this, [=](){
            m->clear();
            m->addAction("bar");
        });
        t.start(2000);
        m->exec();
    }
    
    

    When I now right-click into the tree view, my context menu opens (top, left!), and with each execution of the timer, the context menu gets invisible, and visible again, and so on.

    Note: Although it effectively triggers visibility, it doesn't in the data structures. In my real program, I can trigger the actions by clicking on the area nevertheless.

    I'm not sure if I should report it too fast. I suspect it might depend on some part of my environment (Qt version, KDE, Ubuntu, GPU, whatever, ...). It looks so low-level... Can you reproduce it? Or, is it okay to report it directly without further checks (sorry for my stupid question ;) )?

    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 give more details about your environment ?

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

      P 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Note:
        It was easy to test so i did it on win 10/Qt.57 vs 2015
        I did see some strange flashing so i tried the following

        ....
        connect(&t, &QTimer::timeout, this, = {
        m->setUpdatesEnabled(false) ;
        m->clear();
        m->addAction("bar");
        m->setUpdatesEnabled(true) ;
        });
        ....
        Which seems to reduce it a lot.

        P 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Can you give more details about your environment ?

          P Offline
          P Offline
          pino
          wrote on last edited by
          #4

          @SGaist Hi, thank you! It's a kubuntu 17.04 (with its Qt 5.7.1), amdgpu gpu driver.

          1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Note:
            It was easy to test so i did it on win 10/Qt.57 vs 2015
            I did see some strange flashing so i tried the following

            ....
            connect(&t, &QTimer::timeout, this, = {
            m->setUpdatesEnabled(false) ;
            m->clear();
            m->addAction("bar");
            m->setUpdatesEnabled(true) ;
            });
            ....
            Which seems to reduce it a lot.

            P Offline
            P Offline
            pino
            wrote on last edited by
            #5

            @mrjj Okay, then it's more specific. The setUpdatesEnabled calls haven't changed the behavior here.

            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