M
M
Mercury132020-03-11 18:25:53
Qt
Mercury13, 2020-03-11 18:25:53

Qt: how to disable a HUGE QPushButton menu under Windows?

Here is the code.

#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QMenu>
#include <QMessageBox>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QMainWindow w;
    auto pW = &w;
    QPushButton* btShowMenu = new QPushButton("Some menu", pW);

    QMenu* menu = new QMenu(pW);

    auto lambdaMessage = [pW]() {
        QMessageBox::information(pW, "Clicked!", "Clicked!");
    };

    for (int i = 0; i < 50; ++i) {
        QAction* ac = menu->addAction("Menu item");
        QObject::connect(ac, &QAction::triggered, lambdaMessage);
    }
    btShowMenu->setMenu(menu);

    w.show();
    return a.exec();
}

Before us is a QPushButton with a menu hung on it. The menu is huge and does not fit on top or bottom. When you click on the button, a menu pops up. MOUSE PRESSED. With any shift, even by a pixel, a cursor is formed in the menu, and if the user releases the mouse, it calls the item.

How to debug? Do not suggest reorganization of the menu (the menu is assembled programmatically).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question