[Interest] QGraphicsItem constructor access to scene

Nicholas Yue yue.nicholas at gmail.com
Tue Jun 9 06:07:14 CEST 2020


  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)

Nicholas Yue
Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200608/a771b22c/attachment.html>

More information about the Interest mailing list