QT Table Width Adaptive adjustment method void Setstretchlastsection (bool stretch) reprint

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.