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. QMainWindow::createPopupMenu() shuffles when a menu is checked
Forum Updated to NodeBB v4.3 + New Features

QMainWindow::createPopupMenu() shuffles when a menu is checked

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 541 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
    Kita
    wrote on last edited by Kita
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Do you have a custom model behind the data? Looks like a sorting happens.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kita
        wrote on last edited by
        #3

        Sort of, I updated my image above, I removed the custom model and it still behaves the same.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you create a minimal, compilable example so we can see what you're doing?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kita
            wrote on last edited by jsulm
            #5

            This is the gist of what I'm doing:

            QMenu *ViewFrame::createPopupMenu()
            {
            	
                QMenu *pMenu = QMainWindow::createPopupMenu();
            	do
            	{
            		if (!pMenu)
            			break;
            
            		QList<QAction*> liActions = pMenu->actions();
            
            		APopupMenu *pNewMenu = new APopupMenu(liActions, this);
            
            		pMenu = pNewMenu;
            	}
            	while (false);
            
            	return pMenu;
            }
            

            SPopupMenu.cpp

            APopupMenu::APopupMenu(QList<QAction*> liActions, QWidget *parent 
            	: QMenu(parent)
            {
            
            	for (auto& iter : liActions)
            	{
            		if (!iter)
            			continue;
            
            		addAction(iter);
            	}
            }
            

            And when DockWidget is created I used this

            ADockWidget::ADockWidget(const QString &title, QWidget *parent , Qt::WindowFlags flags )
            	: QDockWidget(title, parent, flags)
            {	
            
            	do 
            	{
            
            		QAction *pAction = toggleViewAction();
            		if(!pAction)
            			break;
            
            		pAction->setData((qulonglong)this);
            		QObject::connect(pAction, &QAction::triggered, this, &ADockWidget::DoSomething);
            	}
            	while(false);
            }
            Christian EhrlicherC 1 Reply Last reply
            0
            • K Kita

              This is the gist of what I'm doing:

              QMenu *ViewFrame::createPopupMenu()
              {
              	
                  QMenu *pMenu = QMainWindow::createPopupMenu();
              	do
              	{
              		if (!pMenu)
              			break;
              
              		QList<QAction*> liActions = pMenu->actions();
              
              		APopupMenu *pNewMenu = new APopupMenu(liActions, this);
              
              		pMenu = pNewMenu;
              	}
              	while (false);
              
              	return pMenu;
              }
              

              SPopupMenu.cpp

              APopupMenu::APopupMenu(QList<QAction*> liActions, QWidget *parent 
              	: QMenu(parent)
              {
              
              	for (auto& iter : liActions)
              	{
              		if (!iter)
              			continue;
              
              		addAction(iter);
              	}
              }
              

              And when DockWidget is created I used this

              ADockWidget::ADockWidget(const QString &title, QWidget *parent , Qt::WindowFlags flags )
              	: QDockWidget(title, parent, flags)
              {	
              
              	do 
              	{
              
              		QAction *pAction = toggleViewAction();
              		if(!pAction)
              			break;
              
              		pAction->setData((qulonglong)this);
              		QObject::connect(pAction, &QAction::triggered, this, &ADockWidget::DoSomething);
              	}
              	while(false);
              }
              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Kita said in QMainWindow::createPopupMenu() shuffles when a menu is checked:

              do
              {
              	if (!pMenu)
              		break;
              
              	QList<QAction*> liActions = pMenu->actions();
              	APopupMenu *pNewMenu = new APopupMenu(liActions, this);
              	pMenu = pNewMenu;
              }
              while (false);
              

              What should this do? It runs exactly once, same for other really strang do .. while(false) loops.

              We need a fully compilable example to reproduce it on our system.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2

              • Login

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