Unsolved Clicking header of QTableView selects top row and causes QTAbleView to emit clicked
-
I have a QTableView. It has a header. I'm stuck using QT 4.something
Clicking on the header changes the row selected. So if I have row five selected, and I click a column in the header, the top row visible becomes selected. No sorting or anything.
I don't want this.
Also, I have connected the QTableView clicked signal to a function, and clicking on the header seems to make that signal fire. I also don't want this.
I want clicking on the header to NOT change the selected row, and also to NOT cause QTableView to fire its clicked signal.
How can I achieve this?
-
Two questions for you: have you called
setSortingEnabled
on your table? And are you usingsetHeaderData
to set the role of the header toQt::DisplayRole
? -
A little unfortunately, I'm maintaining some code in which what I'm working with is a view inherited from QTableView, and a header inherited from QHeaderView.
That said, I think the answer to your first question must be yes, because I spent some time fixing sorting earlier and it does sort (i.e. click header section, and the rows rearrange themselves).
The second; I do not know. I am looking.... The header sections have words in them, so something must be setting that.
-
Yes, I believe setHeaderData is being used.
However, I don't understand what you mean by "set the role of the header to Qt::DisplayRole". I thought that Qt::DisplayRole was the role of various data; I don't understand how an entire header's role can be Qt::DisplayRole.
-
@MoschopsRedux
Hi
The roles is part of the call
bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)But as u can se its default Qt::EditRole so i thinki
@Chris-Hennes ask if u set it as Qt::DisplayRole instead.