For Qtablewidget inheritance There is Qheaderview, and Qheaderview has a method void setstretchlastsection
(bool stretch);
Its formal parameter is a bool type and can be used to set whether it is full width.
Here is an example:
#include <QtGui/QApplication> #include <QtGui/QTableWidget>
#include <QtGui/QHeaderView>
int main (int argc, char *argv[])
{
Qapplication app (argc, argv);
Qtablewidget *table = new Qtablewidget ();
Table->setcolumncount (3);
Table->setrowcount (5);
Table->horizontalheader ()->setstretchlastsection (true); This is the place.
Table->show ();
return App.exec ();
}
*******************************************************/
This method I tried, is able to automatically complete the column header auto-fill, but there is a disadvantage: the rest of the column header is filled with the last column, so the problem is that the last column is wide, seriously affect the aesthetics.
Lucky, everybody crossing, notice, I used a lucky. Why pinch? Because in the landlord's building, I saw a person in the 12 floor said
/*****************************************************
Ui->tablewidget->horizontalheader ()->setresizemode (Qheaderview::stretch);
That's it.
*******************************************************/
I tried, and sure enough, I could finish the fill and divide the column evenly.
All right, here we go, dinner, hoho~.
In the end despise the next QT4 English documents, lack of code examples, let us these beginners how to do ah. There is also a whole QT4 Chinese version of the help document out, all day long to see assistance vomit. God, save it, t_t.
11.2 Update
Today we found that the line also has an adaptive width method, similar to the column, the function is Tablewidget->verticalheader ()->setresizemode (Qheaderview::stretch);
Also, if you add more rows, the line height will not be infinitely smaller, there is a minimum value, about 1 centimeters, anyway, the size is exactly
Looking very comfortable, it will automatically produce a scrollbar.
QT Table Width Adaptive adjustment method void Setstretchlastsection (bool stretch) reprint