Nice2See: QTablewidget fit in Widget
-
Hello,
as you can see in the pic, I have a Table which does not look nice. The last column is cut.
!http://img688.imageshack.us/img688/4107/screenqte.png(Screen)!There must be a property, where I can bind the QTableWidget to its parent, such that when I load a table the optimal width is loaded. The heigth might be fixed, set by myself.
And when I resize the mainWindow the table should be adopted to that..I hope I could explain that..
Cheers Huck
-
I agree with previous poster... Also, I might add, you could find that the last column(s) remains cut: if that's the case, you could either use a smaller font or manually set each column's width to a suitable size (was it setSizeHint?)
--
-
[quote author="peppe" date="1314053648"]It seems to me that the tab Measure has a QWidget inside, and your QTableWidget is inside that widget, and that no layout is installed. Am I correct?[/quote]
Isn't a Layout already installed? Or do you mean another Layout on a upper level?
@
void MainWindow::createVizual()
{
initMainWidget = new QWidget;
initWidTab = new QWidget;
QWidget *testTab = new QWidget;dTabWidget = new QTabWidget; dTabWidget->addTab(initWidTab, tr("Measure")); dTabWidget->addTab(testTab, tr("Test")); QPushButton *button = new QPushButton("My button"); mainLayout = new QVBoxLayout; mainLayout->addWidget(dTabWidget); mainLayout->addWidget(button); initMainWidget->setLayout(mainLayout); setCentralWidget(initMainWidget);
}
@[quote]
was it setSizeHint?
[/quote]
No, I have used:
@
dTableWidget->setGeometry(5, 25, TABLEWIDTH+5, initWidTab->height()-5);
@[quote]
Are you adding the table widget to the tab widget directly, using addTab()?
[/quote]Yes, as you can see above, both Tabs were added by addTab().
[quote]
Bottom line: please show the code that creates this dialog.
Nice looking style, by the way!
[/quote]
Code is above this post. Styles were the standard settings in Qt. I haven't changed any configuration there ;) -
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);
}
@ -
[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.
-
-
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