QStyleOption Animation?
-
Hello. I'm trying to make a button inheriting from QPushButton that has multiple states, represented by which section of the button is highlighted. It might look something like this (on Windows 11):
My plan is to use QStyleOptionButton to paint it to look native, and then to set a clip region and draw it again (but in the mouse over state).There is a problem when doing this, though; any animation a normal QPushButton may have gotten in when the mouse is entering/leaving it is now gone, and I'm not sure how to go about reimplementing it in a cross-platform way. I could store the two states as pixmaps and interpolate their colors, but that wouldn't look right on styles that don't have an animation.
Thoughts?
-
Hi,
Wouldn't a set of custom QRadioButton be more adequate for that ?
-
Having a collection of radio buttons doesn't look fantastic, in my opinion. Considering the way this widget is meant to be used in the context of the rest of the UI, something custom and very cohesively "in one piece" makes sense. I have also seen such buttons on the web, which arguably makes much more sense than in a situation where things are meant to look native, but I want to give it a shot anyway.
I'm not sure that making a widget that inherits from QRadioButton would be my best course of action either, as I wouldn't really gain much other than the parent's "selected" state and maybe the ability to only have one active at a time while neighboring in a layout. I don't have a reason for choosing QPushButton specifically anyway, I just thought it the best option for creating a button-like thing since it already has keyboard navigation (though upon typing this, I realize the multi-state thing would be an issue...)
I am open to other ideas on how to implement this widget /& collection of widgets. However, that still doesn't address the issue of animation.
-
Should it be some kind of breadcrumb ?
If I remember correctly, KDE might have some stuff for you.
-
I've never heard the term breadcrumb in this context. Care to elaborate?
As for the KDE stuff; I'd be willing to look into it, but at this point in time I do not want to rely on the KDE Frameworks. That's the kind of thing I'd be okay with when starting a project, you know? -
Oh, alright. Like Nautilus does for the path.
No, it won't be like that. It would be kind of like how a sidebar behaves, it influences what's visible on the rest of the window. Mixing a sidebar with tabs would be kind of hard though, because the precedence of the state vs. whichever tab is open would be hard to illustrate in the UI. So I've decided on something like this. -
So like the Qt Creator left sidebar ?
-
Yeah. The Qt Creator sidebar & a List View would be equivalent to this multi-state button & a tab widget. Each tab/list view item can be edited in multiple ways, dependent on the state (multi-state button’s current state or selected sidebar item, e.g. Edit, Debug, Design…). Hopefully that makes sense