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. QPainter not drawing the rectangle on QLabel

QPainter not drawing the rectangle on QLabel

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k Views
  • 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.
  • T Offline
    T Offline
    tesmai4
    wrote on last edited by
    #1

    I am displaying image on q QLabel and want to draw a rectangle on it with mouse movement

    Image is loaded correctly and selectionRect has correct co-ordinates. Its co-ordinates are changing with mouse move.

    However, This painEvent is not painting. Could someone help me on this?

    @
    void XWizardPage :: paintEvent(QPaintEvent * e)
    {
    QImage tmp(label1->pixmap()->toImage());
    QPainter painter(&tmp);
    QPen paintpen(Qt::red);
    paintpen.setWidth(3);

    painter.setPen(paintpen);
    painter.drawRect(selectionRect);
    

    }
    @

    Secondly, How can I draw multiple rectangles on my QLabel?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tesmai4
      wrote on last edited by
      #2

      Found the mistake, I was not setting image back to the label.

      Added the following line and it works more than perfect.
      @ label1->setPixmap(QPixmap::fromImage(tmp));@

      How can I avoid the "intermediate drawings":http://tinypic.com/r/2nswhh0/8?
      !http://tinypic.com/r/2nswhh0/8(Problem image)!

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        [quote author="tesmai4" date="1406043994"]How can I avoid the "intermediate drawings":http://tinypic.com/r/2nswhh0/8?
        !http://tinypic.com/r/2nswhh0/8(Problem image)![/quote]

        I guess you need to redraw the part of image that is covered by previous rectangle and then draw your new rectangle.

        BTW(By The Way) If you trying to implement a selection rectangle then take a look on "QRubberBand":http://qt-project.org/doc/qt-5/qrubberband.html#details

        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