Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get item from QGraphicScene
Forum Updated to NodeBB v4.3 + New Features

Get item from QGraphicScene

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 314 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by
    #1

    Hi,

    In QGtaphicsScene I add few items. Then I use the flag QGraphicsItem::ItemSendsGeometryChanges and when the item is moved the program goes to the QVariant GraphicVertical::itemChange ( GraphicsItemChange change, const QVariant & value ) function.
    Here I need to use either QGraphicsScene::items() or QGraphicsScene::itemAt()
    When I use any of these:

    QList<QGraphicsItem*> items = this->scene()->items(Qt::DescendingOrder);
    

    or

    QGraphicsItem *item = this->scene()->itemAt(20, 20, QTransform());
    

    I get an exception error (in debug mode): (why?)
    Application was stopped by the exception...
    1768eb7f-8f47-47ba-a56d-5fb75d12a9dc-image.png

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use a debugger and see where it crashes. I would guess scene() returns a nullptr.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Please_Help_me_DP 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Use a debugger and see where it crashes. I would guess scene() returns a nullptr.

        Please_Help_me_DP Offline
        Please_Help_me_DP Offline
        Please_Help_me_D
        wrote on last edited by Please_Help_me_D
        #3

        @Christian-Ehrlicher yes! As you said this->scene() returnes zero
        but why? How to overcome it?


        EDIT


        I understood now.
        The scene() appears after some operations and as I write my code in itemChange I simply need to write:

            if (this->scene()){ // if the scene() exist then do the following
                QGraphicsItem *item = this->scene()->itemAt(mapToScene(20, 20), QTransform());
                QList<QGraphicsItem*> items = this->scene()->items(Qt::DescendingOrder);
            }
        

        So thank you! you solved my problem!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved