Nice2See: QTablewidget fit in Widget
-
As far as i understood you, the Layout should be insallet here in between?
@
void MainWindow::createTable()
{
QStringList dHeaderLabels;
dHeaderLabels << "Date" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "#Subjects" << "#Sum";/* Table settings and fonts */ dTableWidget = new QTableWidget(0, COLUMCOUNT, initWidTab); dTableWidget->setGeometry(5, 25, TABLEWIDTH+5, initWidTab->height()-5); dTableWidget->setColumnWidth(0, this->TABLEDATEWIDTH); dTableWidget->setColumnWidth(1, this->TABLENUMBERWIDTH); dTableWidget->setColumnWidth(2, this->TABLENUMBERWIDTH); dTableWidget->setColumnWidth(3, this->TABLENUMBERWIDTH); dTableWidget->setColumnWidth(4, this->TABLENUMBERWIDTH); dTableWidget->setColumnWidth(5, this->TABLENUMBERWIDTH); dTableWidget->setColumnWidth(6, this->TABLENUMBERWIDTH); dTableWidget->setColumnWidth(7, this->TABLENUMBERWIDTH); dTableWidget->setColumnWidth(8, this->TABLENUMBERWIDTH); dTableWidget->setColumnWidth(9, TABLENUMBERWIDTH*20); dTableWidget->setColumnWidth(10, TABLENUMBERWIDTH*20); dTableWidget->setHorizontalHeaderLabels(dHeaderLabels); dTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
// dTableWidget->addScrollBarWidget(initWidTab, Qt::AlignRight);
}
@ -
So... where do you create that table (where do you call createTable)? And where do you add that table to a layout?
-
Layout should be between initWidTab and dTableWidget I guess?
-
[quote author="Andre" date="1314443881"]So... where do you create that table (where do you call createTable)? And where do you add that table to a layout?[/quote]
The createTable is created in the Constructor:
@
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
init();
}void MainWindow::init()
{
createActions();
createMenus();
createStatusBar();
createVizual();
createTable();
setWindowTitle( tr("%1 v%2.%4").arg(APPNAME).arg(MAJOR_VERSION).arg(MINOR_VERSION) );
}
@And the is not added to a Layout. I just set the parent as initWidTab as in the code above.
-
I think the best solution would be to add your Table to a layout.
-
Instead of a Widget.. I'll try that at home asap. Thanks.
-
Basically:
Except for the top level widget, every widget needs to be in a layout, and every layout needs to be either in another layout or set as the layout for a widget.If one item disconnected from this tree, then the layouting will not work properly.
-
Hello,
this is my architecture:
mainLayout
+--> dTabWidget (TabWidget)
+--> initWidTab (Tab Item)
+--> dTableWidget (TableWidget)I was trying putting a layout in betweeen initWidTab and dTableWidget:
@
QVBoxLayout importTabLO = new QVBoxLayout;
importTabLO.addWidget(initWidTab);
dTableWidget = new QTableWidget(0, COLUMCOUNT, importTabLO);
@/mainwindow.cpp:65: error: no matching function for call to 'QTableWidget::QTableWidget(int, const quint32&, QVBoxLayout&)'
importTabLO is a Layout and thus not accepted - a widget is required as I understood?
I guess, casting would not solve this.
Anybody any suggestions?
Cheers Huck
-
You are doing it the wrong way around. Currently, you are trying to put the tab widget in the layout. Instead, put the table widget in the layout, and set the layout as the layout on the tab widget:
@
QVBoxLayout importTabLayout = new QVBoxLayout;
dTableWidget = new QTableWidget(0, COLUMNCOUNT);
importTabLayout->addWidget(dTableWidget);
initWidTab->setLayout(importTabLayout);
@
Note that then putting widgets in layouts, they will be reparented automatically, so there is not even a need to set a parent explicitly for the table widget. -
That works fine. Thank you Andre!
I have a small question regarding the Mainwindow's width.
I would like to adopt the mainwindows width to that table, depending on the numbers size' stored in my tables columns.
For instance when I have big numbers in each col, my table might be real wide. So I would like to adopt my mainwindow, such that I dont need any Horizontal scrollbar..Thank you in advise.
Cheers Huck