Results 1 to 4 of 4

Thread: Overridden pos() in QGraphicsItem to link to QAbstractItemModel

  1. #1
    Join Date
    Oct 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Question Overridden pos() in QGraphicsItem to link to QAbstractItemModel

    Gday,

    I have subclassed QGraphicsPixmapItem in order to link the position of the item directly to a data model (subclassed from QAbstractItemModel).

    I have overridden pos to return values from the model using appropriate QModelIndex objects (I am using PySide for Qt 4.8):

    Qt Code:
    1. def pos(self):
    2. x = self.model.data(self.x_index)
    3. y = self.model.data(self.y_index)
    4. return QPointF(x, y)
    To copy to clipboard, switch view to plain text mode 

    However, pos is never called! I assumed the view (via the scene) would call pos for each item when drawing, however from the source it looks like the view/scene gets the position of a QGraphicsItem directly through 'd_ptr'.

    Is what I am trying to do possible? I was hoping there was some method that would form the single point of access to pos but it looks like this is not the case.

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overridden pos() in QGraphicsItem to link to QAbstractItemModel

    pos() is not a virtual method so overriding it does not make sense.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    lrb (19th October 2013)

  4. #3
    Join Date
    Oct 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Overridden pos() in QGraphicsItem to link to QAbstractItemModel

    Cheers. It's a shame Qt wasn't implemented that way, would've made it simple to link graphics items to data models.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overridden pos() in QGraphicsItem to link to QAbstractItemModel

    I do not agree. pos() is merely a getter for part of the internal item matrix. If you want to control position of an item through a model, you can freely do that by teaching your model to use pos() and setPos() to modify the item position.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 27th February 2013, 11:55
  2. Replies: 4
    Last Post: 12th May 2011, 00:07
  3. Replies: 11
    Last Post: 5th May 2011, 14:05
  4. How to link a Push Button with a Web link ???
    By prajnaranjan.das in forum Newbie
    Replies: 3
    Last Post: 10th December 2010, 07:25
  5. QSystemTrayIcon: Overridden balloon msg
    By further in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2008, 10:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.