Details
-
Bug
-
Resolution: Out of scope
-
P2: Important
-
4.2.1
-
None
-
243926
Description
It seems QMenu somehow figures out it's geometry before aboutToShow is emitted. The following example demonstrates this problem.
The menu will be cleared and have some items added to it when:
A) The menu is about to show
B) The button is clicked
If you start the app and just click the arrow you'll see the menu appear in a strange location.
If you close the menu and reopen it will appear in a more reasonable location.
If you restart the app and click the button before bringing up the menu it will appear in right position the first time as well.
#include <QWidget>
#include <QWidget>
#include <QToolButton>
#include <QMenu>
#include <QApplication>
#include <QRect>
#include <QAction>
#include <QVBoxLayout>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0)
: QWidget(parent)
public slots:
void sl_updateMenu()
private:
QToolButton *tb_arrow;
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Widget w;
const QRect screenSize = QApplication::desktop()->availableGeometry(&w);
w.move(screenSize.width()-w.width(), screenSize.height()/3);
QRect r(QPoint(0, 0), w.sizeHint());
r.moveRight(screenSize.right());
w.setGeometry(r);
w.show();
return app.exec();
}
Rejected:
Unfortunately QMenu does not support populating in a slot connected to aboutToShow(). QMenu's positioning algorithm relies on its size.
Update: Reopened after we discovered this is a regression. See change 22887.