Den 07-01-2016 kl. 21:44 skrev Murphy, Sean:
I'm trying to figure out the right way to show some feedback to the user and
I'm stuck. Here's the setup:
- I have a QTabWidget, that has three tabs, one for live data, one for archived
data, and a third tab that doesn't having much to do with this particular
issue, other than it exists.
- On the first tab we plot a live feed of data from a variety of sensors
- Also on this tab, there is a "Take Snapshot" button
- Pressing the "Take Snapshot" button should make a copy of the current plot
data under the second tab while keeping the first tab (the live data) as the current tab
index
- On the second tab, there's a child tab widget that shows the snapshots taken
above, one snapshot per tab
This works fine, except that there's no real indication to the user that pressing the
"Take Snapshot" button actually worked until the user clicks on the second tab
and sees that the snapshot exists, so we'd like to add some sort of visual feedback that
it was successful. Ideally, I'd like to blink the background color of *just* the second
tab a couple times to let the user know something changed over there. But looking through
QTabWidget, QTabBar, there doesn't seem to be any way of changing the background color of
an specific, individual tab. I can change the text color of a specific tab using
QTabBar::setTabTextColor(), but after trying that the effect is just a little too subtle.
The closest thing I can find is through stylesheets using the QTabBar::tab:middle
subcontrol and pseudostate, which I just luck out that it works for me because I only
have 3 tabs, and I'm trying to change the middle tab. If we add more tabs later, that
won't work, unless I switch it to using QTa
bBar::tab:last and then change the behavior that the archived data is always
on the last tab.
Are there other options to change the color, or does anyone else have a better
idea of how to do provide feedback to the user? The only other viable options I
see is that I could either:
- change the text on the second tab to somehow reflect something changed
(like add an * or something)
- blink an icon on the second tab using QTabBar::setTabIcon(int index, const
QIcon & icon)
I would probably prefer something like an overlay message popping up for
a few seconds or (a bit nineties style) a status bar message. Another
would be to have a subtle small icon overlay float from the button up to
the tab.
I was trying to think if there were ways to hack around a QStyle proxy
to do the flashy bit, but I'm not sure without spending a fair amount of
time. The trick in this case is always the same idea:
1) Override only exactly what you need, in this case the drawing of a
single tab.
2) Find a way to realize that you're currently painting the thing you
want to change.
3) Override the painting of that single item, call the base class
painter for all others.
This is a generic QStyle trick that can be used for many evil purposes.
The problem with it is that it's quite hard to debug for anyone that
doesn't know you have done it - imagine the poor developer going "where
the f!#ยค%& does that come from"? Hurting maintainability is usually a
bad idea.
The trick has much more of an appeal if you already have a lot of QStyle
stuff in your code.
Bo Thorsen,
Director, Viking Software.
--
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest