PDA

View Full Version : Where to start on a graphical "tooltip"



zarkzervo
11th March 2011, 07:20
My users want a graphical representation instead of a tooltip, i.e. a tooltip-looking hovering rectangle that shows the detailed information of a node as a graphical representation.

I have looked into the sourcecode of qtooltip.cpp and was thinking of making a similar class. As QToolTip is tailored to create a QLabel that shows text, I plan to subclass QGraphicsView and show this as a hovering rectangle with no frame-fluff.

Is that the right class to start with? Any other tips? Any other baseclass that is better for this purpose?

And I noticed that QToolTip have a separate internal singleton class QTipLabel. Is that really necessary? Shouldn't my class be able to make an instance of itself if necessary? Or is it much cleaner to maybe not subclass the access class, but rather subclass the extra singleton class from QGraphicsView (or some other class)?

I plan to have the same type of static function GraphicalTooltip::showGraphicalTooltip(Node*, Widget*) to ease the use.

SixDegrees
11th March 2011, 07:42
QGraphicsView might be a bit heavyweight for something like this. You're able to display an image in a QLabel; I'd consider that approach first.

As far as singletons go, I'm no fan of them. However, there can only be one tooltip visible at any given time, which was probably the designer's reason for selecting a singleton

zarkzervo
11th March 2011, 07:47
QGraphicsView might be a bit heavyweight for something like this. You're able to display an image in a QLabel; I'd consider that approach first.

But I'm displaying a QGraphicsItem. I will also want to update the graphics if this tool stays up to show the updated data.

And as for singleton, I came to the same conclusion. I would only allow one tooltip at a time and it should rather be updated with the current item's graphics.

zarkzervo
8th April 2011, 07:03
I went for the subclassing of QGraphicsView and it works like a charm. I made a singleton of it so only one would be visible and would check the placement when a new request to show the tooltip was made. I could then reuse the tooltip (for the same tool or if they would overlap) and would make a new when necessary.