Unsolved Updating widget stylesheet in succession
-
@EaccB said:
So, originally, I was going to do something along the lines of:
Nah, don't do that. A pre-pass to mark the selected ones in some way is a better option.
Also, I'll probably be moving to dynamic properties
I'm usually skeptical about those in tight loops like this, because it's a string based dictionary lookup and a type cast (variant to whatever). Not great. I usually only use them to mark a single thing that I won't be checking too often, but you'll have to measure how much it matters to you.
Would a flicker show in this case?
If you use that
setUpdatesEnabled
method I mentioned then no. Otherwise you'll have to see for yourself, but I wouldn't rely on it. My advice is to focus on modifying only what is needed to change and only doing it once. -
Might be best if I describe my actual problem in more detail.
I have a series custom widgets which are displayed in a grid. Each widget can be either "Active" or "Inactive". This. is achieved via 2 functions, activate() and deactivate(). Amongst other things, these functions set the widget's border to orange and grey respectively.
Back in Mainwindow, I have a table view where each row is associated with a QList which contains a struct of data which will be passed to the widget for processing (also contains a pointer to the relevant widget). If the QList for the selected row contains a struct pointing to a widget, that widget should be "Active". Everything else should be "Inactive".
On selection of a row, I see no other way to update the widgets than checking whether every widget in the grid is present in the QList of the selected row. An alternative is to populate each QList with a struct for every widget and specify which should be active/inactive, although not too keen on this idea.
-
Hold the pointers to the widgets in your struct so you can directly access them when the struct is moved from active to inactive and back.
-
I think we got out wires crossed. The structs contained in the QLists are only for widgets which should be active for that row. Setting the relevant widgets to active is trivial, as you say access them directly. Setting everything else to inactive seems to be more difficult.
-
Then hold the inactive ones in another QList and move them around.
-
How about using
QWidget::setEnabled(bool)
to toggle the enabled state of the widgets. The stylesheet can then have a different style for enabled and disabled states. One thing to consider here is that child widgets would inherit this state. So, this works for non-interactive widgets only (like showing text). -
I'm not sure what you mean. Could you provide an example please?
-
Hold an additional container with the inactive ones. When you move them between the two containers you know which style to set.
-
In which case each row would need to have 2 QLists, one for Active and Inactive. Seems a bit redundant to store empty structs for widgets which are inactive.
-
@EaccB said in Updating widget stylesheet in succession:
Seems a bit redundant to store empty structs for widgets which are inactive.
I never said you should store some structs, only the pointers to the widgets. But it's up to you. If you need the information you have to store it somewhere.
-
How about something like this?:
setEnabled(false); for all widgets: widget.deactivate(); for widgets in QList: widget.activate(); setEnabled(true);
I don't think that would be terribly inefficient. What do you think?
-
It depends on the size but yes. Still don't understand why you can't the state when it changes from active to inactive and back.