[Qt4-preview-feedback] Custom QGraphicsLayout
Mihail Naydenov
mlists at ymail.com
Sun Feb 8 16:22:38 CET 2009
Hello, Im new to Qt, and just started to learn it few weeks ago.
Im interested in QGraphicsView framework in general, and as an exercise I decided to write a custom QGraphicsLayout.
Well, I knew it will be hard, but I turned out to be harder, and what's more - impossible without looking the actual Qt code (for QGraphicsLinearLayout and QGraphicsWidget for example)
Anyway, maybe Im just a hopeless noob...
still I have 2 questions that I think are adequate:
First.
The docs for QGraphicsLayoutItem::setOwnedByLayout say:
"Sets whether a layout should delete this item in its destructor or not. ownership must be true to in order for the layout to delete it."
But the actual QGraphicsLayout deos not recpect this! Only its subclasses respect this (QGraphicsLinearLayout) by adding code to the destructor.
Second.
The QGraphicsLayout's addChildLayoutItem function is commented as:
"This function is called from subclasses to add a layout item to a layout.
It takes care of automatically reparenting graphics items, if needed.
If layout item is already in a layout, it will remove it from that layout."
But this function is defined as private, and there is no (legal) way a subclass of QGraphicsLayout to call it!
Again QGraphicsLinearLayout does use this feature, illegally, by including the private headers and classes for QGraphicsLayout.
In general automatic reparenting should be part of QGraphicsLayout API as the docs suggest:
QGraphicsLayoutItem::setGraphicsItem:
"If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take advantage of the automatic reparenting capabilities of
QGraphicsLayout it should set this value. ..."
Right now the only automatic reparenting one can have with "pure" QGraphicsLayout is through QGraphicsWidget and its setLayout function, but that does not solve the problem of adding items to a layout, that get reparent in order to show up.
So if I want a custom layout with these two important (basic) features, I either have to subclass from QGraphicsLinearLayout, which is overkill and not The Right Thing, or use the techniques from the Qt source, which is ugly or plain wrong.
If there is a "right" workflow for writing a real custom layout, what it should be?
Thank you
MihailNaydenov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt4-feedback/attachments/20090208/fa4247b1/attachment.html
More information about the Qt4-feedback
mailing list