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 QPainter pos
Forum Updated to NodeBB v4.3 + New Features

Get QPainter pos

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.2k 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.
  • B Offline
    B Offline
    beowulf
    wrote on last edited by
    #1

    My image is rendered inside a widget if it is larger than the widget can be moved, so I need to know what is the current position of the image.

    @
    _result_image = QImage();
    _result_image.load("D:\Desert.jpg");
    @

    @
    void OpenCVWidget::paintEvent(QPaintEvent *)
    {

    QPainter painter(this);
    
    painter.drawImage(QPoint(0, 0), _result_image);
    
    painter.end();
    

    }

    void OpenCVWidget::mousePressEvent(QMouseEvent *event)
    {

    event->accept();
    

    }

    void OpenCVWidget::mouseMoveEvent(QMouseEvent *event)
    {

    event->accept();
    

    }

    void OpenCVWidget::mouseReleaseEvent(QMouseEvent *event)
    {

    event->accept();
    

    }
    @

    -- 0x00

    1 Reply Last reply
    0
    • B Offline
      B Offline
      beemaster
      wrote on last edited by
      #2

      Try Qt Quick, it's really what you need. Use "Flickable":http://qt-project.org/doc/qt-4.8/qml-flickable.html

      @

      import QtQuick 1.1

      Flickable {
      width: 200
      height: 200
      contentHeight: image.height
      contentWidth: image.width
      Image {
      id: image
      source: "http://www.symbiantweet.com/wp-content/uploads/2011/05/qt-logo.jpg"
      }
      }
      @

      You can change source to "D:\Desert.jpg"

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beowulf
        wrote on last edited by
        #3

        I don't want to Qt Quick. :(

        -- 0x00

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          [quote author="beemaster" date="1351362895"]Try Qt Quick, it's really what you need.[/quote]I doubt it...

          To the question:

          • have a member variable save the current camera position (or image position - ends up being the same thing). Let's call it QPoint mImagePos.
          • In mouse press event, save the current cursor position to QPoint mDragStartCursorPos and save the current image position mImagePos to QPoint mDragStartImagePos
          • In mouse move event, calculate the distance vector between mDragStartCursorPos and the current cursor position. Then set the current image position mImagePos to mDragStartImagePos plus the distance vector. And, of course, call repaint() to cause a paint event.
          • On the mouse release event, finally set the image position mImagePos to mDragStartImagePos plus the distance vector.
          • In the paint event, draw the QImage at mImagePos, always.

          Note that you could also implement this via the QPainter::translate functionality. This will allow dragging of a whole scene painted by the painter, without needing dynamic coordinates for the objects (like we used mImagePos here). This depends on what you really want: Single object dragging, or scene dragging.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            beowulf
            wrote on last edited by
            #5

            Thank you DerManu.

            It's a little confusing, but I'll try.

            -- 0x00

            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