[Interest] QGraphicsItem constructor access to scene

mail at herrdiel.de mail at herrdiel.de
Tue Jun 9 08:22:55 CEST 2020


Hi,

I usually solve these kind of problems by having a very light
constructor, accepting the need to call a MyClass::initialize(...)
later. Is that unthinkable in your case?

You can pass the scene item on construction, store its address as a
member and use it later, when your scene is initialized.

I don't know if that's regarded to be a proper or a bad way to solve the
problem, it just works for me.

Would be interesting to know, if such an approach would be frowned upon
by professionals.

Sebastian



Am 09.06.2020 um 06:07 schrieb Nicholas Yue:
> Hi,
>
>   During the constructor phase of my QGraphicsItem derive class, I
> need to perform some QFont related information. The font information
> may be obtained via scene object but my study of the constructor stage
> is that it is not initialized yet.
>
>   The derived class is added to the scene via the addItem() call.
>
>   Is there another way to access the scene in a QGraphicsItem
> constructor ?
>
>   For now, I am passing the scene object explicitly
>
> class NodeItem(QtWidgets.QGraphicsItem):
> def __init__(self, name, attribues, scene):
> '''scene is only required because we need to query the font
> '''
> super(NodeItem, self).__init__()
>
>   Q : Does my need to use scene in the constructor indicates that my
> class was not designed properly?
>
>   Q : Are there other ways to obtain the font information in the
> constructor other than ?
> font = scene.property('font')
> fm = QtGui.QFontMetrics(font)
>
> Cheers
> -- 
> Nicholas Yue
> Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
> Custom Dev - C++ porting, OSX, Linux, Windows
> http://au.linkedin.com/in/nicholasyue
> https://vimeo.com/channels/naiadtools
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest

-- 
http://www.classintouch.de - Tablet-Software für Lehrer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200609/1679abf1/attachment.html>


More information about the Interest mailing list