November 28, 2011

strangelookingnerd strangelooki..
Lab Rat
21 posts

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

November 28, 2011

fluca1978 fluca1978
Ant Farmer
524 posts

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.

November 30, 2011

strangelookingnerd strangelooki..
Lab Rat
21 posts

So there is no possibility of having a visible focus on more than one widget?

November 30, 2011

fluca1978 fluca1978
Ant Farmer
524 posts

As far as I know, no. And it will not depend on Qt either, it is the underlying windowing system that establishes that. The best you can do, but I would definitively avoid it, is to force a window theme so that inactive items will not become grayed, but this would confuse your users.

November 30, 2011

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

November 30, 2011

strangelookingnerd strangelooki..
Lab Rat
21 posts

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!

November 30, 2011

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

November 30, 2011

fluca1978 fluca1978
Ant Farmer
524 posts
Andre wrote:
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.

November 30, 2011

strangelookingnerd strangelooki..
Lab Rat
21 posts
Andre wrote:
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!

 
  ‹‹ Difference between double click and Open button in QFileDialog      [SOLVED] About signals and slots timing.. ››

You must log in to post a reply. Not a member yet? Register here!