Project

General

Profile

CentralWidget size in WPanel

Added by Adrian L over 3 years ago

Hi,
Can somebody tell me how to fill all available space in Wpanel Widget? How to make panelCentralContainer the biggest as possible?
In my code it is as small as possible :(

//****************************************************************************************
// main.cpp
//****************************************************************************************

#include <Wt/WApplication.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WHBoxLayout.h>
#include <Wt/WVBoxLayout.h>
#include <Wt/WPanel.h>

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

HelloApplication::HelloApplication(const Wt::WEnvironment& env) : Wt::WApplication(env)
{
    setTitle("test");

    // Menu Panel:
    auto rootLayout = root()->setLayout(Wt::cpp14::make_unique<Wt::WVBoxLayout>());

    auto panel = rootLayout->addWidget(Wt::cpp14::make_unique<Wt::WPanel>(), 1);
    panel->setCollapsible(false);
    panel->setStyleClass("panel panel-primary");
    panel->setTitle("Title");

    auto panelCentralContainer = panel->setCentralWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());
    panelCentralContainer->set
    panelCentralContainer->decorationStyle().setBorder(Wt::WBorder{Wt::BorderStyle::Solid, Wt::BorderWidth::Thick, Wt::StandardColor::Red});
}

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

    return Wt::WRun(argc, argv, ApplicationRunEventHandler);
}

Replies (3)

RE: CentralWidget size in WPanel - Added by Adrian L over 3 years ago

This line should be removed to compile code, I've missed it.

panel->CentralContainer->set

RE: CentralWidget size in WPanel - Added by Stefan Bn over 3 years ago

I'm currently seeing the exact same problem in my code. I have a WPanel inside a layout that stretches to maximum available size.

Usually I would do something like

panelCentralContainer->setMinimumSize(WLength(100, LengthUnit::Percentage), WLength(100, LengthUnit::Percentage));

or use a CSS-Style { width: 100%; height: 100%; } on panelCentralContainer. But neither works and I can't get my central widget to fill the entire panel space.

Maybe the Wt-developers can give some insight on how the size of the CentralWidget of a WPanel is handled please?

(For the time beeing I'm using a fixed size for the CentralWidget, but that breaks my entire style of nicely adapting widgets to browser window size :-( )

RE: CentralWidget size in WPanel - Added by Stefan Bn over 3 years ago

I found a solution! In combination with a Bootstrap style one has to modify the CSS style of the panel body so that it takes the entire space and also the same for the central widget.

CSS:
.panel-fill-wh > .panel-body
{
    height: 100%;
    width: 100%;
}

.my-fill-wh
{
    width: 100%;
    height: 100%;
}

Wt:
panel->addStyleClass("panel-fill-wh");
panelCentralContainer->addStyleClass("my-fill-wh");

:-)

    (1-3/3)