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. Adding Items to Reimplemented QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

Adding Items to Reimplemented QGraphicsScene

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.1k Views 2 Watching
  • 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by ModelTech
    #1

    I have reimplemented QGraphicsScene to a class called MGraphicsScene as I would like to disable moving any items in case the QGraphicsScene is used for a certain purpose that I have made available through variable Mode. I have the following code for this:

    void MGraphicsScene::addItem(QGraphicsItem *Item) {
    
        if (Mode == INSPECTOR)
            Item->setFlag(QGraphicsItem::ItemIsMovable, false);
    
        QGraphicsScene::addItem(Item);
    }
    

    On top of this, I have reimplemented MGraphicsScene to a class called StructuralScene. I am trying to add items to such StructuralScene by using the following code:

    void StructuralScene::onAddedPort(PortDefinition *Connector) {
    
        PortDiagram *New = new PortDiagram(Connector);
        New->setZValue(-150);
        addItem(New);
    }
    

    PortDiagram is a subclass of QGraphicsObject.

    For some reason however, the PortDiagram items are not added at all to the scene. I have checked this by inspecting the result of QGraphicsScene::items() after performing StructuralScene::onAddedPort, but this list is indeed empty. Any ideas what is wrong here, i.e., why the items are not added to the scene?

    1 Reply Last reply
    0
    • ModelTechM Offline
      ModelTechM Offline
      ModelTech
      wrote on last edited by
      #2

      The problem stays if I remove the MGraphicsScene::addItem method completely. So, in which direction should I be looking for potential errors?

      1 Reply Last reply
      0
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by
        #3

        I found the problem: I forgot to set the scene for my view! How stupid...

        mrjjM 1 Reply Last reply
        0
        • ModelTechM ModelTech

          I found the problem: I forgot to set the scene for my view! How stupid...

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ModelTech
          Well on the bright side, you found it yourself. :)

          1 Reply Last reply
          0
          • ModelTechM Offline
            ModelTechM Offline
            ModelTech
            wrote on last edited by
            #5

            Yes :) But I only found it because I was trying to access the scene in a context menu elsewhere ;)

            mrjjM 1 Reply Last reply
            0
            • ModelTechM ModelTech

              Yes :) But I only found it because I was trying to access the scene in a context menu elsewhere ;)

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ModelTech

              Hehe, well all productive programmers will have some sort of whoops from time to time. :)

              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