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. Multiple GraphicsViews for one Scene
Forum Updated to NodeBB v4.3 + New Features

Multiple GraphicsViews for one Scene

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

    Hi,

    Windows 10 x64, Qt 4.8.1, Qt 5.6.2, MinGW 4.9.2, VisualStudio 2015

    I have a problem with a QGraphicsScene. I am using multiple graphicsview for one scene. I am changing the color of the items when item selection changes.
    When I am selecting items in the first view, the items are not painted as selected in the second view. When I am selecting items in the second view, it's the same. The items are always painted as selected in the first view but never in the second view.
    Everything else works fine, like moving or resizing items.

    Has anyone an idea?

    regards
    Oliver

    raven-worxR 1 Reply Last reply
    0
    • S stvokr

      Hi,

      Windows 10 x64, Qt 4.8.1, Qt 5.6.2, MinGW 4.9.2, VisualStudio 2015

      I have a problem with a QGraphicsScene. I am using multiple graphicsview for one scene. I am changing the color of the items when item selection changes.
      When I am selecting items in the first view, the items are not painted as selected in the second view. When I am selecting items in the second view, it's the same. The items are always painted as selected in the first view but never in the second view.
      Everything else works fine, like moving or resizing items.

      Has anyone an idea?

      regards
      Oliver

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @stvokr said in Multiple GraphicsViews for one Scene:

      I am changing the color of the items when item selection changes.

      how do you do that exactly?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • S Offline
        S Offline
        stvokr
        wrote on last edited by stvokr
        #3

        My class MyItem inherits from GraphicsItem and I reimplemented the paint() function.

        void MyItem::paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* )
        {
            QPen pen( Qt::green, 1 );
            if( isSelected() )
                pen.setColor( Qt::red );
        
            ...
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          stvokr
          wrote on last edited by
          #4

          Ok,

          I think this has something to do with the update call. The second view is not updated just like the first view, when the selection of the items changes.

          Another thing is very weird.
          I found out that all items, which are visible in the scene rect of the first view, are updated correctly (painted as selected). All other items which are not visible in the first view but in the second view are updated there.

          Ideas?
          Or is this a Bug?

          regards
          Oliver

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            The code of QGraphicsItem::setSelected reveals that update() is called, so a repaint should be scheduled (unless isVisible() returns false, which should not be the case here).

            You could check the 40000 chips examples, which has multiple views, and see if it works there.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stvokr
              wrote on last edited by
              #6

              Hi,

              thanks for the hint.
              The example is working.

              I found the problem. I compared the example to my project and I called

              setCacheMode( DeviceCoordinateCache );
              

              in the construtor of my class MyItem (and I don't know why). And now it works.

              I think it was a copy and paste problem from an old project...
              And Closed.

              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