Multiple Widgets in QDialog -> Multiple “active” selections
Hey!
I got a config dialog as a QDialog with multiple widgets to configure my main application. So i got QComboBoxes, QListView, QTableView and so on.
I got some kind of “feature” to select an item in a QListView (QStandardItemModel) and add a selection (the text of the QStandardItem) at a selected position in a QTableView (QStandardItemModel). The adding works perfect but i lack of some visual feedback to the user.
Since if i select an item in the QListView, it turns blue as an “active” selection. Now I select an item in the QTableView to alter it.
Result: the QTableViews selection becomes “active” and therefore blue. The previous selection in the QListView turns greyish, like a nonactive selection. I’d like to keep this selection also active and blue.
I guess its because you can only have one active selection in a QDialog/QWidget. Is there any way to change this behavior?
so long…
8 replies
This is a behaviour that depends on the component that has the focus. All the selections are still enabled, but the colour changes due to the component that looses the focus to give it to another one. I believe that having all the selection “active” will confuse the user that no more understands on which component he is working.
Actually, you can achieve this.
There are a few ways to achieve what you want. You could fiddle with the style, by subclassing QProxyStyle and overriding how your listview gets rendered. Another approach to do the same, is to create a custom delegate for your list view. That way, you can also fully control the rendering of each item, and you can make items look the same irrespective if the widget has focus or not.
The current approach I’m working on includes the QItemSelectionModel::selectionChanged() signal, connected to a method as slot which paints the selected item as desired and resetting the rest. I doubt the efficiency of this approach on larger tables, but since there are only like 20-30 items I think it could do the job :)
I’ll let you know if it worked out!
Actually, you can achieve this. There are a few ways to achieve what you want. You could fiddle with the style, by subclassing QProxyStyle and overriding how your listview gets rendered. Another approach to do the same, is to create a custom delegate for your list view. That way, you can also fully control the rendering of each item, and you can make items look the same irrespective if the widget has focus or not.
Right! Never thought about that for this scenario.
No, that is not the right approach. Painting is done from the paintevent, and I have already laid out the options you have to manipulate that. Your way is not going to work.
Actually it worked with some tweaks here and there. But there were some side-effects I didn’t think of. I tried creating custom delegates, which works as expected!
You must log in to post a reply. Not a member yet? Register here!


