Results 1 to 2 of 2

Thread: How to paint (QPainter) on a label ?

  1. #1
    Join Date
    Apr 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to paint (QPainter) on a label ?

    Hi,
    I have several labels on my screen(mainwindow.ui) And I need to draw on them(Overlay).
    Unfortunately "Qpainter" just draws behind labels.

    Qt Code:
    1. void MainWindow::paintEvent( QPaintEvent * event )
    2. {
    3. QPainter painter(this);
    4. painter.setPen(QPen(Qt::black, 2));
    5.  
    6. //ui->pushButton->clearFocus();
    7. //ui->pushButton->setAutoFillBackground(true);
    8. //ui->pushButton->setBackgroundRole();
    9. //ui->pushButton->setForegroundRole();
    10.  
    11.  
    12. //painter.setBackgroundMode();
    13.  
    14. path.moveTo(qrand() % 80, qrand() % 320);
    15. path.cubicTo(200, 80, 320, 80, 480, 320);
    16. painter.setPen(QPen(Qt::black, 8));
    17. painter.drawPath(path);
    18. }
    To copy to clipboard, switch view to plain text mode 
    I searched for lots of beheviars belonging "QPainter" and "QLabel".

    Can you guide me how can I fix it?


    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to paint (QPainter) on a label ?

    Some tips:
    You paint on the main window "canvas".
    Labels are put on top of the main window.
    So, if you want to paint on top of the labels, you need to paint in the labels

  3. The following user says thank you to tbscope for this useful post:

    d@nyal (29th May 2010)

Similar Threads

  1. QPainter::begin: Cannot paint on a null pixmap
    By sabeesh in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2010, 18:03
  2. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 07:25
  3. Replies: 5
    Last Post: 20th October 2009, 07:18
  4. Replies: 5
    Last Post: 7th September 2009, 20:57
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.