[Interest] Questions about QGraphicsWidget
Jason H
scorp1us at yahoo.com
Tue Aug 7 19:02:21 CEST 2012
I think you're kinda thinking about it wrong.
First, there is QGraphicsItemGroup, which would probably do what you want, and automatically provides a boundingRect() as the unsion of all child bounding rects.
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.
HTH
________________________________
From: BRM <bm_witness at yahoo.com>
To: Interests Qt <interest at qt-project.org>
Sent: Tuesday, August 7, 2012 12:36 PM
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?
TIA,
Ben
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120807/96d0f62c/attachment.html>
More information about the Interest
mailing list