Details
-
Bug
-
Resolution: Cannot Reproduce
-
P3: Somewhat important
-
4.5.0
-
None
Description
On Linux, if the attribute WA_TranslucentBackground is set in the event loop of a QMenu (menu.exec()), the menu do not close itself when it loose the focus.
Here is a code to reproduce the problem (right click in the main window, then click elsewhere in the window):
#include <QApplication>
#include <QContextMenuEvent>
#include <QMenu>
#include <QPlastiqueStyle>
#include <QWidget>
class Style : public QPlastiqueStyle
{
public:
Style() : QPlastiqueStyle()
{
}
void polish(QWidget *widget)
{ if (qobject_cast<QMenu*>(widget)) widget->setAttribute(Qt::WA_TranslucentBackground); }};
class MainWindow : public QWidget
{
public:
MainWindow() : QWidget(), style(new Style)
{
}
~MainWindow()
{ delete style; }void contextMenuEvent(QContextMenuEvent *event)
{ QMenu menu; for (int i = 0; i < 10; i++) menu.addAction(QString("Action ") + QString::number(i + 1)); menu.setStyle(style); menu.exec(event->globalPos()); }private:
Style *style;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow w;
w.show();
return app.exec();
}