I have a QButton with an associated QMenu. The QMenu contains a single QWidgetAction with an associated widget.

Now I want to change the content of the widget contained in the menu at some point, and have the QMenu resize itself when shown so that the QMenu is the appropriate size for the content in the widget.
For instance:
Qt Code:
  1. QPushButton* button = new QPushButton("Button",parent);
  2. QMenu* menu = new QMenu(button);
  3. button->setMenu(menu);
  4. MyWidget* customWidget = new MyWidget(menu);
  5. QWidgetAction* menuWidget = new QWidgetAction(menu);
  6. menuWidget->setDefaultWidget(customWidget);
  7. menu->addAction(menuWidget);
  8. //Attach a signal that would allow the customWidget to update its contents prior to being shown
  9. QObject::connect(menu,SIGNAL(aboutToShow()),customWidget,SLOT(updateContent()));
  10. //The 'updateContent' slot may add or remove child widgets to 'customWidget' causing its size to change
To copy to clipboard, switch view to plain text mode 
What I want to happen is that each time the menu is about to be shown the widget will update its content and the QMenu will be shown with the appropriate size to display the content of the widget.

What currently happens is that the QMenu takes its size from whatever the initial size of the customWidget object is the first time it is shown. Updating the content of the customWidget object does not have any effect on the size of the containing menu on later showings of the menu. That is, the QMenu will always be the same size as the first time it was shown regardless of what modifications I make to the customWidget object.

This was working at one point and I can't for the life of me figure out what has changed.