Set tablewidget Adaptive column widths and set auto-width

Source: Internet
Author: User

It is easy to know the adaptive column width on the internet, 100% is not left blank display, here still mention:

/*设置表格是否充满,即行末不留空*/ui->tableWidget->horizontalHeader()->setStretchLastSection(true);

Set the effect after 100% not empty:

Before QT5, the automatic width can be achieved by the following program:

/*QT5版本之前设置自动等宽*/ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);

But to the QT5 this will not work, need to be set by the following code:

/*设置tablewidget等宽*/QHeaderView* headerView = ui->tableWidget->horizontalHeader();headerView->setSectionResizeMode(QHeaderView::Stretch);/*或者下面的代码*/ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);

Set the effect after the auto-equal width:

http://blog.csdn.net/freeape/article/details/48713393

Set tablewidget Adaptive column widths and set auto-width

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.