Bug #1409
closedWTreeView resizing inside a WHBoxLayout
0%
Description
A WTreeView widget grows horizontally inside a WHBoxLayout when its data is updated and if it has a border. This was raised as part of a forum dicussion [[[http://redmine.emweb.be/boards/2/topics/4815]]]. The code below demonstrates the problem. If the setBorder call is removed, then everything works as expected and the tree view stays at a constant width. Please also note that even without a border the same effect occurs if the data updates alternate between needing a scrollbar and not needing one. I can provide a second example code for this if required. The problems occur with Wt code taken from the git on 20 Aug 2012.
#include <Wt/WApplication>
#include <Wt/WHBoxLayout>
#include <Wt/WStandardItem>
#include <Wt/WStandardItemModel>
#include <Wt/WTreeView>
#include <Wt/WGroupBox>
#include <Wt/WPushButton>
using namespace std;
using namespace Wt;
class WtTestApp : public WApplication
{
public:
WStandardItemModel* m_model;
bool m_dataset;
WtTestApp(const WEnvironment& env) :
WApplication(env),
m_dataset(false)
{
m_model= new WStandardItemModel(0, 1);
WTreeView* tv;
tv= new WTreeView();
tv->decorationStyle().setBorder(WBorder(WBorder::Solid, 1));
tv->setModel(m_model);
WGroupBox* groupBox= new WGroupBox("Group");
WPushButton* button= new WPushButton("Refresh", groupBox);
button->clicked().connect(this, &WtTestApp::refresh);
WHBoxLayout* l= new WHBoxLayout(root());
l->setContentsMargins(0, 0, 0, 0);
l->addWidget(tv, 1);
l->addWidget(groupBox, 1);
refresh();
}
void refresh(void)
{
m_model->clear();
if (m_dataset)
{
m_model->appendRow(new WStandardItem("Row 4"));
m_model->appendRow(new WStandardItem("Row 5"));
m_model->appendRow(new WStandardItem("Row 6"));
m_model->setHeaderData(0, Horizontal, boost::any(string("Data 2")));
}
else
{
m_model->appendRow(new WStandardItem("Row 1"));
m_model->appendRow(new WStandardItem("Row 2"));
m_model->appendRow(new WStandardItem("Row 3"));
m_model->setHeaderData(0, Horizontal, boost::any(string("Data 1")));
}
m_dataset= !m_dataset;
}
};
WApplication* createApp(const WEnvironment& env)
{
return new WtTestApp(env);
}
int main(int argc, char *argv[])
{
return WRun(argc, argv, &createApp);
}
Updated by Koen Deforche about 12 years ago
- Status changed from New to InProgress
- Target version set to 3.2.3
Hey,
I couldn't reproduce this problem with latest git. Could you confirm that the latest git version already fixes this issue or with what browser you do see the issue ?
Regards,
koen
Updated by Stas Magill about 12 years ago
Hi Koen,
The behaviour is indeed different with the latest git, but it still doesn't look right. In both Chrome and Firefox the tree view takes up most of the available width. The tree view and the group box both have a stretch factor of 1, so I would have expected the two controls to take up 50% of the width each.
Thanks.
Updated by Koen Deforche about 12 years ago
- Status changed from InProgress to Resolved
Hey,
Thanks, this was indeed a regression, I've fixed this in my git copy.
Regards,
koen
Updated by Koen Deforche about 12 years ago
- Status changed from Resolved to Closed
Fixed in Wt 3.2.3 RC1.