Fusion style QTableView leaving shadow highlight only on single cell
-
I'm creating a QTableView and configured it such that the selection behavior is "SelectRows".
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
And this works great, doing exactly what I want. I'm playing around with theming and I'm liking the look of "fusion" and with this the selection behavior still work as expected - select a single cell and the whole row is selected. Without the fusion theme "selecting away" deselects the whole row. However, with the fusion theme when I "select away" a "shadow highlight" is left behind, which only highlights the specific cell that had been clicked.
In this situation the table view is larger than what the rows can fill, so by "select away" I mean select into the unfilled table view area. It would appear that even though there is a "shadow highlight" on the cell, the row (nor the cell) is considered selected, so I would expect that the highlight would be completely cleared. Is there any way in which I can control/force that?
Note: I'm using Qt 6.7
-
Hi,
On which OS are you working ?
Can you provide a minimal compilable exemple showing this behavior ? -
Thanks for the prompt reply!
I'm working in Windows 11 and I've created a minimal (compilable) example that I've pushed to GitHub showing the issue that I'm running into.
Locally my system is in a dark theme with purple as the accent color.
-
Use the windowsvista style instead to see if the problem persist.
-
Ultimate the same thing can be seen with the windowsvista style, just not as pronounced. With the windowsvista the cell retains a dashed line.
With the windowsvista style I feel that it's more clearly noted that this is "where you last clicked" whereas the fusion style makes it seem like it's actually highlighted.
Is this behavior something that can be turned off?
-
@cancech Please simplify your example - no need for a model or extra mainwindow. The less classes the less to debug here.
-
@Christian-Ehrlicher I'm not sure how to simplify my example. I don't see how to add data to the QTableView without creating my own model and I believe that mainwindow.h, mainwindow.cpp, and mainwindow.ui are all three needed. Short or removing the mainwindow.ui and reproducing the layout in code that is.
-
@cancech simply create a tableview, add a stringlist model and show it. No mainwindow or other stuff needed.
-
@Christian-Ehrlicher Got it! I've updated the example to remove the unnecessary pieces.
-
Ok, now I know what you mean. This is the marking for the currently index. There is a difference between selected indexes and current index. That's the same as when you select a file in windows explorer and then click on a blank area - the previously selected row is still painted somewhat different.
-
@Christian-Ehrlicher Ahh, I see. So it's there to indicate "if you press the arrow keys, there is where you'll be starting from". Considering that I'm using whole row selection, shouldn't the whole row be the index then? I would presume that pressing the left/right arrows wouldn't really do anything
-
@cancech In Qt there is only one 'current index' possible. And you can't change this anywhere - you can only change the selection behavior.
-
@Christian-Ehrlicher Gotcha, thanks so much for all the help and figuring out what's going on!
-
@cancech You might reset the current index flag during painting by overriding https://doc.qt.io/qt-6/qabstractitemview.html#initViewItemOption
-