[Interest] Questions about QGraphicsWidget
bm_witness at yahoo.com
Tue Aug 7 19:26:49 CEST 2012
> From: Jason H <scorp1us at yahoo.com>
>To: BRM <bm_witness at yahoo.com>; Interests Qt <interest at qt-project.org>
>Subject: Re: [Interest] Questions about QGraphicsWidget
>I think you're kinda thinking about it wrong.
You're right - I probably am. I'm quite use to QWidget still, and trying to get my head around some of the differences for QGraphics.
>First, there is QGraphicsItemGroup, which would probably do what you want, and automatically provides a boundingRect() as the unsion of all child bounding rects.
An interesting idea.
I had been planning on using the QGraphicsItemGroup to capture the larger widget set with all the lines, text, and data displays; while having this widget just deal with the data and its overlay. And looking a little closer I guess I can add a group to be within another group...I'll have to look into this more.
>When custom drawing your item always draw it "native" resolution. let the Scene work out the scaling and scaled bounding rect. You only need to worry about yourself at 1:1 scaling.
I'd be glad to once I can figure it out. KISS is a very good principle to live by.
> From: BRM <bm_witness at yahoo.com>
>Subject: [Interest] Questions about QGraphicsWidget
>I'm working on a QGraphicsWidget version of something I already have a QWidget version of; namely because I need to add some features where I need to overlay items, lines, and text in a way that QWidget does not support (namely the addition of the text information) - presently I'm just focused on getting to the point of equivalence with what I had under QWidget. In doing so I have taken my one QWidget and converted it into a series of QGraphicsWidgets, and added a parent QGraphicsWidget that will contain at most two of the sub-widgets - the data being drawn, and
its ideal overlay. (I originally had just one QGraphicsWidget but found it simplified things if I split stuff out. I figured this would be an advantage since I can overlay stuff in QGraphics* where I could not under QWidget.)
>Question #1: The parent widget has two widgets within it. At this time I'm not using a QGraphicsLayout of any sort as none seem to match doing the overlay I need - that is, the two widgets will be in different Z-levels (1 and 2), and if both are visible then they will be nearly the same coordinates in their parent coordinate system. Or am I missing something and this would be supported by one of the existing QGraphicsLayouts? Do I really even need a QGraphicsLayout to manage these, or is there a simpler way to do it? I'm thinking the geometry would be that of the farthest extremities of the combination of the two widgets when both are visible, or just the one widget when only one is visible. The parent widget will likely
sit in a QGraphicsLayout of some sort when I am done.
>Question #2: I'm having an issue with scaling of the drawing. If I understand QTransform::scale() correctly, then it maps the coordinates being used from one coordinate system to another. I am trying to keep the drawing within the boundaries of the widget itself, but using the boundingRect().contains(pointToDraw) does not keep any points from being drawn when the leave the boundingRect(). I didn't have to worry about this with QWidget as QWidget clipped what was being drawn (or at least displayed) on the boundaries of the widget; while QGraphicsWidget doesn't do that - it'll gladly leave artifacts. Am I missing an easy way to keep it from leaving artifacts?
>Interest mailing list
>Interest at qt-project.org
More information about the Interest