Project

General

Profile

Bug #9622

Wrong positioning of the WPopupMenu

Added by Andreas Frolov 8 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
01/17/2022
Due date:
% Done:

0%

Estimated time:

Description

Wt sometimes shows WPopupMenu truncated even though there is enough space.

int buttonCounter = 0;

class ContextButton : public Wt::WPushButton
{
public:
    ContextButton(int itemCounter = 20)
    {
        setMaximumSize(130, 30);
        setText(std::string("Button ") + std::to_string(++buttonCounter));
        setAttributeValue("oncontextmenu", "event.cancelBubble = true; event.returnValue = false; return false;");
        mouseWentUp().connect([this, itemCounter](const Wt::WMouseEvent& event) {
            if (event.button() == Wt::MouseButton::Right)
            {
                Wt::WPopupMenu popup;
                for (int i = 0; i < itemCounter; ++i)
                {
                    popup.addItem(std::string("Item ") + std::to_string(i));
                }
                popup.exec(event);
            }
        });
    }
};


class Application : public Wt::WApplication
{
public:
    Application(const Wt::WEnvironment& env);
};

Application::Application(const Wt::WEnvironment& env)
    : Wt::WApplication(env)
{
    auto rootLayout = root()->setLayout(std::make_unique<Wt::WVBoxLayout>());
    for (int i = 0; i < 20; ++i)
    {
        rootLayout->addWidget(std::make_unique<ContextButton>());
    }
    rootLayout->addStretch(1);
}

int main(int argc, char **argv)
{
    return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
        return std::make_unique<Application>(env);
    });
}

Files

Screenshot 2022-01-17 145024.png (28.1 KB) Screenshot 2022-01-17 145024.png Andreas Frolov, 01/17/2022 02:54 PM

No data to display

Also available in: Atom PDF