setSizeAware and getting the height of widgets
Added by Michael Leitman about 12 years ago
Hello out there :)
Due to my problems getting the actual client-side height of my widgets i write a short project,
to explain what i want and have already done.
I'd like to create a visual Link between two parts of my Application
(as mentioned in an earlier post here: http://redmine.webtoolkit.eu/boards/2/topics/2849#message-3630)
To connect these parts (they have completely individual and flexible height) i need to get the actual height of the widgets.
I already tried to use "setSizeAware(true)"
for all of my container widgets,
but if i call wwidgetContainer->height()
or height().toPixels()
i get always strange values?
(a seen in the console output in the screenshot i attached)
What did i miss?
How can i get the actual height of the widgets and containers in the browser?
I also attached a test project (TestSizeAware.rar)
any help is much appreciated,
- regards, the incredible Leitman
TestSizeAware.rar (8.27 KB) TestSizeAware.rar | |||
screenshot.PNG (34.4 KB) screenshot.PNG |
Replies (4)
RE: setSizeAware and getting the height of widgets - Added by Koen Deforche about 12 years ago
Hey,
The actual size for a layout-size-aware widget is communicated only in the layoutSizeChanged() methods (which you print).
The width and height of a widget merely returns the value that was set for it.
If no value is set, it is (usually) WLength::auto.
If a value is set, this is returned.
When converting a length to pixels, then it returns 0.
Regards,
koen
RE: setSizeAware and getting the height of widgets - Added by Michael Leitman about 12 years ago
I am really sorry to be back here,
but I simply just don't get it :(
What I want is a visual connection between my widgets (http://redmine.webtoolkit.eu/attachments/613/Layout_with_visual_link.PNG)
but I can't figure out, what to do to get the height of the widgets in the browser :(
Maybe anyone can help me with a few Questions?
Alignment
As mentioned in the reference: "This method propagates the client-side width and height of the widget when the widget is contained by a layout manager and setLayoutSizeAware(true) was called."
So i have to put the widgets in a LayoutManager per addWidget(widget, row, col)
which itself is nested in a Widget (or widgetContainer) that has set LayoutSizeAware to true.
for example:
m_layout = new WGridLayout(); // the bottom Layout: | | | |
m_layout->setHorizontalSpacing(0); // | | | |
m_layout->setVerticalSpacing(0); // | | | |
m_layout->setContentsMargins(0, 0, 0, 0);
SizeAwareContainerWidget *container = new SizeAwareContainerWidget(); // this container gets the layoutSizeChanged method if added
WGridLayout *inner_layout = new WGridLayout(); // to forward the sizeChange -> add nested LayoutManager
inner_layout->setHorizontalSpacing(0);
inner_layout->setVerticalSpacing(0);
inner_layout->setContentsMargins(0, 0, 0, 0);
for (int idx_row = 0; idx_row < 3; ++idx_row)
{
inner_layout->addWidget(new DropDownWidget(ss.str()), idx_row, 0); // here comes my DropDownWidget from the example project above
}
container->setLayout(inner_layout);
m_layout->addWidget(container, 0, idx_col, 0);
this->setLayout(m_layout, AlignLeft);
This works, i get the output of layoutSizeChanged with the new width and height :)
But how can i set the aligment of the widgets?
if if try container->setLayout(inner_layout, AlignTop);
(which i want) instead of setLayout without Alignment,
the layoutSizeChanged of the dropDownWidget is never called :(
How can i align my widgets, so that the horizontal space inside the container is not split between them?
(see screenshot "alignment.png")
when is layoutSizeChanged called?
In my DropDownWidget, onClick i set a nested Widget to invisible per
this->m_wContainer->setHidden(!this->m_wContainer->isHidden());
which reduces the height of my widget in the browser.
If I do so and click, the widget size changes, but onLayoutChanged gets never called.
And if i want to set the actual size in pixel IN the onLayoutChanged method:
virtual void layoutSizeChanged( int w, int h )
{
std::cout << " size changed to: " << w << ", " << h << "\n";
if (w != width().toPixels() || h != height().toPixels())
{
std::cout << " size was: " << width().toPixels() << ", " << height().toPixels() << "\n";
resize(WLength(w, WLength::Pixel), WLength(h, WLength::Pixel));
}
}
it gets called over and over again.
And if a react to a inside onClick Event inside my DropDownWidget as:
resize(width(), height());
parent()->resize(parent()->width(), parent()->height());
nothing happens, the onLayoutSizeChanged gets not called.
How can i force a call of onLayoutSizeChanged?
Any help is appreciated,
i am searching and try and error for days now ;(
- the incredible Leitman
alignment.PNG (29.4 KB) alignment.PNG |
RE: setSizeAware and getting the height of widgets - Added by Michael Leitman about 12 years ago
Any help? Any suggestion?
Anyone?
... please? ;(
RE: setSizeAware and getting the height of widgets - Added by Koen Deforche about 12 years ago
Hey,
You should add an empty container widget with stretch 1 as a last widget which will get all the remaining space.
Regards,
koen