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. Disable multiple selection in QGraphicsScene
Qt 6.11 is out! See what's new in the release blog

Disable multiple selection in QGraphicsScene

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.7k 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.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by
    #1

    Hi,

    I add few QGraphicsItem in QGraphicsScene. For each item I set the flag setFlags(QGraphicsItem::ItemIsSelectable);. Now when I launch the application and pick few items while CTRL is hold then I get every pressed item is selected.
    Is there a way to disable multiple selection?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I don't think there's an easy way to do that. One possibility would be to subclass QGraphicsView and re-implement its mousePressEvent. Create a new QMouseEvent object that is the copy of the one you are getting minus the modifier and then call the base class implementation with that new event.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Please_Help_me_DP 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        I don't think there's an easy way to do that. One possibility would be to subclass QGraphicsView and re-implement its mousePressEvent. Create a new QMouseEvent object that is the copy of the one you are getting minus the modifier and then call the base class implementation with that new event.

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

        @SGaist Thank you for response
        Is there a significant difference whether to implement mousePressEvent in QGraphicsView or in QGraphicsScene class?

        1 Reply Last reply
        0
        • Please_Help_me_DP Offline
          Please_Help_me_DP Offline
          Please_Help_me_D
          wrote on last edited by Please_Help_me_D
          #4

          I have another similar question.
          I implemented few movable items and there is interesting things. When there is a selected item on the scene and I fast move the mouse without stop and click and hold mouse_1 on the unselecteditem then I move both items: the item I hold and an item is selected (like my computer has no time to change selected item and move the both)
          Is there a way to overcome this?

          I tried to use QThread::sleep() in MyItem::itemChange() this helps but no matter how long is sleep parameter the selected item still do a little position change (few millimeters and the it stops)
          The same result I get if I implement in in MyItem::itemChange():

          scene()->clearSelection();
          this->setSelected(true);
          

          This happens in both debug and release mode
          1.png

          SGaistS 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Because the extended selection is implemented in the QGraphicsView::mousePressEvent.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • Please_Help_me_DP Please_Help_me_D

              I have another similar question.
              I implemented few movable items and there is interesting things. When there is a selected item on the scene and I fast move the mouse without stop and click and hold mouse_1 on the unselecteditem then I move both items: the item I hold and an item is selected (like my computer has no time to change selected item and move the both)
              Is there a way to overcome this?

              I tried to use QThread::sleep() in MyItem::itemChange() this helps but no matter how long is sleep parameter the selected item still do a little position change (few millimeters and the it stops)
              The same result I get if I implement in in MyItem::itemChange():

              scene()->clearSelection();
              this->setSelected(true);
              

              This happens in both debug and release mode
              1.png

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              As for your next question, I wonder if you are not triggering the rubber band selection somehow. You can try to disable it.

              Note: it's never a good idea to put your main thread to sleep because you are going to block the event from processing events and thus make your GUI somewhat unresponsive.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              Please_Help_me_DP 1 Reply Last reply
              2
              • SGaistS SGaist

                As for your next question, I wonder if you are not triggering the rubber band selection somehow. You can try to disable it.

                Note: it's never a good idea to put your main thread to sleep because you are going to block the event from processing events and thus make your GUI somewhat unresponsive.

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

                @SGaist thank you for reply
                I didn't use rubber band selection (at least I didn't write the code with somehow similar to it)
                I decided to turn off the selection flag and do my own "selection" when the item is clicked (setPen wider).

                Sorry for answering so late.

                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