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. Drawing a rectangle on the image displayed on UILable
Forum Updated to NodeBB v4.3 + New Features

Drawing a rectangle on the image displayed on UILable

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

    Dear All,
    I displayed an image on UIlabel as follow
    @QImage rImg = QImage(templ->width,templ->height, QImage::Format_RGB888);
    pixma = QPixmap::fromImage(rImg);
    ui->label_2->setPixmap(pixma);@

    I also have a rectangle with x, y, width and height information.
    How can I display the rectangle on the image?
    Thanks.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Very easy in QML or QGraphicsView. A bit trickier with QPainter. Also not straightforward with QLabel.

      You need to either blend the images and then set the result on your QLabel, or create 2 QLabels on top of each other, and place the rectangle on the one above (you also need to set the label to be transparent).

      Oh, and if by rectangle you mean QRect, then you need to change that. QRect is just a mathematical abstraction (an object storing x, y, width and height), it has no graphical representation as such (hence it residing in QtCore).

      (Z(:^

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thomas11live.com.sg
        wrote on last edited by
        #3

        Now I changed to QGraphicsView. How to draw a rectangle with a color?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          General page on the framework: "link":http://qt-project.org/doc/qt-4.8/graphicsview.html.

          And here is your "rectangle item":http://qt-project.org/doc/qt-4.8/qgraphicsrectitem.html.

          (Z(:^

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thomas11live.com.sg
            wrote on last edited by
            #5

            I draw the rectangle as below.
            scene2->addRect(showRect.x, showRect.y, showRect.width, showRect.height);

            How to get the rectangle in color?

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              I think you need to use "setBrush()":http://qt-project.org/doc/qt-4.8/qabstractgraphicsshapeitem.html#setBrush method.

              (Z(:^

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JacobsRichard
                wrote on last edited by
                #7

                Well except the coding part there is one more way for graphical representation is use of 3D charting with support of HTML5, for that "Dashboard Chart":http://www.koolchart.com.

                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