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. Is there way to make a line in Label widget?
Qt 6.11 is out! See what's new in the release blog

Is there way to make a line in Label widget?

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

    Dear guys,

    In my application, Label widget shows raw bitmap image from my device.
    Then, I need to make a line in Label widget.

    When I use drawLine() function (like shown blow), this line is made not in Label but main dialog
    so I could not see the line because Label covers the line.

    @
    void MainWindow::paintEvent(QPaintEvent *)
    {
    if(image2.Buffer == NULL)
    return;

    QPainter p;
    p.begin(this);
    
    QImage Image(800, 750, QImage::Format_ARGB32);
    loadImageData((uchar *)image2.Buffer, 750, 800, &Image);
    
    
    m_buffer = QPixmap::fromImage(Image);
    ui->ViewLable->setPixmap(m_buffer);
    
    p.drawLine(20,400,800,400);
    
    p.end();
    
    Image.detach();
    

    }
    @

    So, I would like to know the way to make a line on Label widget.

    Thanks,

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Subclass QLabel, and reimplement its paintEvent instead of the one of your main window. Then, you can simply overpaint the line directly on the widget, instead of on the image.

      The problem with the code above, is that you create the painter on the this object: the MainWindow itself. If you wanted to paint on the image, you should have created it on the Image object. However, I don't get why you first create an image at all, only to convert it to a pixmap a few lines later.

      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