简体   繁体   中英

QTableWidget show scroll bar

I would like the horizontal scroll bar to appear whenever there is text eliding. Such that the user won't have to resize the whole GUI. How would I do this?

This is what I have coded:

ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
ui->tableWidget->resizeColumnsToContents();

I also tried enabling scrollbar to appear always, but scrolling to the very right doesn't do anything.

在此处输入图片说明

If I set textElideMode to ElideNone , the text from the 2nd column is partially hidden and no scrollbar appears.

在此处输入图片说明

QHeaderView::Stretch will stretch the column width to the available space. Use QHeaderView::ResizeToContents to make the column wide enough to display the content, resulting in a horizontal scroll bar if necessary.

This will have a couple of side effects of which I'm not sure you want them.

  • There will probably be no more ellipsis in the elided text.
  • If all of the values in your Hash column are very small, then that column will be very thin, so there might be 'empty' space next to that column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM