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. [SOLVED]QGraphicsView's dragMode
Qt 6.11 is out! See what's new in the release blog

[SOLVED]QGraphicsView's dragMode

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.0k 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.
  • D Offline
    D Offline
    dmitrij
    wrote on last edited by
    #1

    Hello,

    I have a small problem. After creating the class which is inherited from QGraphicsView and reimplementing mouse events I got a small problem: I can't move items. Yes, the flag QGraphicsItem::ItemIsMovable is set. I guess I need to implement my own mechanism for that. But before it I want to ask you, guys: Is in this situation another way for getting both mouse events and saving dragMode functionality which is provided by default?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rokemoon
      wrote on last edited by
      #2

      Is in this situation another way for getting both mouse events and saving dragMode functionality which is provided by default?
      yes, you need in all mouse events give event further to QGraphicsView.
      @
      void YoueView::mousePressEvent(QMouseEvent *event)
      {
      //your code
      //and in the end just do this
      QGraphicsView::mousePressEvent(event);
      }
      @
      and do this for mouse move and release event.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dmitrij
        wrote on last edited by
        #3

        Thank you! It works!
        I didn't consider that at all.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rokemoon
          wrote on last edited by
          #4

          [quote author="dmitrij" date="1320052884"]Thank you! It works!
          I didn't consider that at all.[/quote]
          You are welcome :)
          Please mark the post as [Solved], thank's.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            [quote author="dmitrij" date="1320052884"]Thank you! It works!
            I didn't consider that at all.[/quote]

            As general rule of thumb:
            If you want to add functionality in a virtual method you reimplement, make sure to call the base class' implementation too. Whether before or after your code depends, of course. And make sure you call the direct base class' implementation (not one of that's parents), even if that class doesn't actually reimplement the method - it might do so in the future and you're on the safe side in that case.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dmitrij
              wrote on last edited by
              #6

              [quote author="Volker" date="1320062134"]

              As general rule of thumb:
              If you want to add functionality in a virtual method you reimplement, make sure to call the base class' implementation too. Whether before or after your code depends, of course. And make sure you call the direct base class' implementation (not one of that's parents), even if that class doesn't actually reimplement the method - it might do so in the future and you're on the safe side in that case.[/quote]

              Thank you! Now I have full understanding about what's going on in QT's framework.

              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