开发者

QMenu::addAction does not work when called inside a specific if-clause

开发者 https://www.devze.com 2023-03-29 09:06 出处:网络
I encountered a very strange problem: if( currentWidgetType_m == WidgetTypesMap ) { qDebug() << \"Here we are!\";

I encountered a very strange problem:

if( currentWidgetType_m == WidgetTypesMap ) {
      qDebug() << "Here we are!";
      optionsMenu_mp->addAction( tr( "Change visibility" ),
         this, SLOT( VisibleItemClicked() ) );

      optionsMenu_mp->addSeparator();
}

optionsMenu_mp->addAction( tr( "Change statistics" ),
      this, SLOT( StatisticsItemClicked() ) );
optionsMenu_mp->addAction( tr( "Change view" ),
      this, SLOT( ViewItemClicked() ) );

The condition is true in this case and the debug message shows in the output, but the "Change visibility" action does not ap开发者_如何学Pythonpear in the menu.

Any ideas what might be causing this?

Best regards


The problem was caused by the QMenu not updating. I solved the problem by recreating the QAction that held the QMenu.

0

精彩评论

暂无评论...
验证码 换一张
取 消