How to keep header from being selected when there is one item in a QTableWidget?
Asked Answered
B

3

7

I can't seem to keep the horizontal header from being selected when I select a single row in a QTableWidget.

Example:

alt text

How can I prevent the header from being selected too? This only happens when one row is in the table. If it has more than two rows, then it works as expected and only the row itself is selected.


Note: I have set

ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);

so that the entire row is selected when the user clicks a cell.

Baudoin answered 23/8, 2010 at 0:8 Comment(0)
C
6

I created a test and observed the same behavior and I'm not sure what the intended behavior is. I was able to prevent it by setting horizontalHeaderHighlightSections to false but I'm not sure if that is an optimal solution.

Chatter answered 23/8, 2010 at 2:11 Comment(0)
T
6

Maybe method setHighlightSections() can help:

ui->tableWidget->horizontalHeader()->setHighlightSections(false); 
Truditrudie answered 31/5, 2012 at 16:0 Comment(0)
T
0

In addition to the answer of @theerapong-thongprom you can also use:

 ui->tableWidget->horizontalHeader()->setSectionsClickable(false); 

So, the sections would also have no animation while clicking on them.

Tiebout answered 2/10, 2024 at 11:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.