Project

General

Profile

The Popup Menu jumps to the bottom of the page instead of hiding

Added by Ali Ali 7 days ago

I am newbie to WT, however after reading this page: https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WPopupMenu.html i tried to create a popup menu as follow:

#include <Wt/WApplication.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WPopupMenu.h>
#include <Wt/WMessageBox.h>

using namespace Wt;

class test : public WApplication
{
private:
    /* data */
public:
    test(const WEnvironment &env) : WApplication(env)
    {

        root()->resize (500, 500);
        root()->decorationStyle().setBorder (WBorder(BorderStyle::Solid, 2, StandardColor::Red));
        auto btn = root()->addNew<WPushButton>("testPopUp");
        auto txt = root()->addNew<WLineEdit>();
        txt->setWidth (WLength (30, LengthUnit::FontEm));
        txt->setPlaceholderText("selected item will show here ...");
        auto popup = std::make_unique<WPopupMenu>();
        popup->addItem("item1")->triggered().connect ([=]{txt->setText("item1 selected.");});
        popup->addItem("item2")->triggered().connect ([=]{txt->setText("item2 selected.");});
        popup->addItem("item3")->triggered().connect ([=]{txt->setText("item3 selected.");});
        popup->addItem("item4")->triggered().connect ([=]{txt->setText("item4 selected.");});
        btn->setMenu (std::move (popup));
    }    
    ~test();
};

test ::~test()
{
}

int main(int argc, char **argv)
{

    return WRun(argc, argv, [](const WEnvironment &env)
                { return std::make_unique<test>(env); });
}

After loading, the popup menu is hidden and will be displayed by selecting the button, but after selecting an item or canceling the menu, it jumps to the bottom of the page instead of hiding.

The build environment is :

Operating System: Ubuntu 22.04.5 LTS
Kernel: Linux 6.8.0-49-generic
Architecture: x86-64
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

I built and ran the program whit this command:

g++ -std=c++14 -o test.wt main.c++ -lwthttp -lwt
./test.wt --docroot . --http-address 0.0.0.0 --http-port 9090 -c ../resources/wt_config.xml

error.png (11.3 KB) error.png