I cant set the with of columns of a WTableView widget
Added by Peter Müller almost 7 years ago
Hi!
I got a problem with WTableView and column width
I have a WTableView and I want to set the column with but it seems to be ignored.
I tried to find the problem, and it seems the css code generated by Wt is wrong.
Most probably I do something wrong that leads to this css code, but I cant find it!
I have a screenshot (image1_browser-screen.jpg) attached, that shows the result in the browser and the resulting css as it is sent to the browser in two other screenshots where I made the width settings.
The Table width is set correct in the outer div>, but then it is set to the default for a 3 column table in the inner div>.
This can be seen in the attached file html-css1.jpg
The column width settings my code does are ignored and the default width is used.
This can be seen in the attached file html-css2.jpg
Here is an excerpt of my code that builds the layout:
// At first the general application framework:¶
root ()->setStyleClass ("applicationRoot");
Wt::WVBoxLayout *rootVBox = new Wt::WVBoxLayout ();
root ()->setLayout (rootVBox);
rootVBox->setSpacing (0);
rootVBox->setContentsMargins (0, 0, 0, 0);
Wt::WContainerWidget *kopfzeile = new Wt::WContainerWidget ();
rootVBox->addWidget (kopfzeile);
applikationsStack = new Wt::WStackedWidget ();
rootVBox->addWidget (applikationsStack, 1);
Wt::WContainerWidget *fusszeile = new Wt::WContainerWidget ();
rootVBox->addWidget (fusszeile);
for (size_t i = 0;i < applikationsVektor.size ();i++) {
if (!applikationsVektor [i].compare ("app0")) {
EWApp0 *app0 = new EWHauptMenue ();
applikationsStack->addWidget (app0);
}
... repeated for each top level application
}
kopfzeileMenue->setCurrentIndex (0);
applikationsStack->setCurrentIndex (menuIndex);
// Now the main menu for the application:¶
EWHauptMenue::EWHauptMenue (WContainerWidget *parent) : Wt::WContainerWidget (parent) {
zugangsVerwaltungTabWidget = new Wt::WTabWidget (this);
benutzerTab = new EWBenutzer ();
zugangsVerwaltungTabWidget->addTab (
benutzerTab,
Wt::WString::tr ("EWEinstellungen_EWHauptMenue_tab_label_benutzer"),
Wt::WTabWidget::LazyLoading
);
}
// Now the Subapplication:¶
EWBenutzer::EWBenutzer (WContainerWidget *parent) : Wt::WContainerWidget (parent) {
formStack = new Wt::WStackedWidget (this);
formBenutzerListe = new EWBenutzerListe (formStack);
formBenutzerBearbeiten = new EWBenutzerBearbeiten (formStack);
}
// And the list display:¶
EWBenutzerListe::EWBenutzerListe (WContainerWidget *parent) : Wt::WContainerWidget (parent) {
this->setId ("EWBenutzerListe");
Wt::WVBoxLayout *formVBox = new Wt::WVBoxLayout ();
formVBox->setSpacing (10);
this->setLayout (formVBox);
Wt::WText *ueberschrift = new Wt::WText (Wt::WText::tr ("EWEinstellungen_EWBenutzerListe_liste_ueberschrift"));
ueberschrift->addStyleClass ("h1");
formVBox->addWidget (ueberschrift, 1, Wt::AlignLeft);
Wt::WContainerWidget *formListe = new Wt::WContainerWidget ();
formListe->setId ("formListe");
formListe->resize (Wt::WLength ("0"), Wt::WLength ("1"));
formVBox->addWidget (formListe);
Wt::WHBoxLayout *formListeHBox = new Wt::WHBoxLayout ();
formListe->setLayout (formListeHBox);
benutzerListeModel = new EWBenutzerListeModel (this);
benutzerListeView = new Wt::WTableView ();
benutzerListeView->setModel (benutzerListeModel);
benutzerListeView->setId ("BenutzerListe");
benutzerListeView->setColumnResizeEnabled (false);
benutzerListeView->setHeaderAlignment (0, Wt::AlignCenter);
benutzerListeView->setColumnAlignment (0, Wt::AlignRight);
benutzerListeView->setColumnAlignment (1, Wt::AlignLeft);
benutzerListeView->setColumnAlignment (2, Wt::AlignLeft);
benutzerListeView->setAlternatingRowColors (true);
benutzerListeView->setRowHeight (28);
benutzerListeView->setHeaderHeight (28);
benutzerListeView->setSelectionMode (Wt::SingleSelection);
benutzerListeView->setEditTriggers (Wt::WAbstractItemView::NoEditTrigger);
*benutzerListeView->setWidth (200 + 7 + 250 + 7 + 400 + 7 + 2);
benutzerListeView->setColumnWidth (0, 200);
benutzerListeView->setColumnWidth (1, 250);
benutzerListeView->setColumnWidth (2, 400);*
formListeHBox->addWidget (benutzerListeView);
formListeHBox->addStretch (1);
Wt::WPushButton *buttonNeu = new Wt::WPushButton (Wt::WText::tr ("EWEinstellungen_EWBenutzerListe_liste_button_neu"));
this->addWidget (buttonNeu);
}
What's wrong? i can't find it.
Thank you for every hint to solve this!
image1_browser-screen.jpg (49.3 KB) image1_browser-screen.jpg | This is how the table is displayed by firefox | ||
html-css1.jpg (162 KB) html-css1.jpg | here is the html and css where the table and header with is set (wrong!) | ||
hml-css2.jpg (165 KB) hml-css2.jpg | Here is the html and css where the column with ist set (wrong!) |
Replies (1)
RE: I cant set the with of columns of a WTableView widget - Added by Peter Müller almost 7 years ago
Hi!
I found out, that the problem occurs, when the Model Content is changed.
After each change I must reset the column with etc. in the view.
What's the correct way to handle changes in the model content in this model-view scenario ?