Quaxton Hale
Quaxton Hale

Reputation: 2520

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.

enter image description here

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

enter image description here

Upvotes: 1

Views: 7939

Answers (1)

PrisonMonkeys
PrisonMonkeys

Reputation: 1229

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.

Upvotes: 2

Related Questions