Results 1 to 5 of 5

Thread: How can I draw with brush on QLabel?

  1. #1
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How can I draw with brush on QLabel?

    I have QLabel on the form. I use it to show an image like this:

    Qt Code:
    1. QString fileName = "image.jpg";
    2. QImage image(fileName);
    3. ui->label->setPixmap(QPixmap::fromImage(image.scaled(349,228, Qt::KeepAspectRatio, Qt::FastTransformation)));
    4. ui->label->adjustSize();
    To copy to clipboard, switch view to plain text mode 

    How can I paint with brush on my QLabel with mouse? For example, i press left mouse key, then dragging, it lefts brush'es line, then the results - on the QLabel.

  2. #2
    Join Date
    Oct 2010
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can I draw with brush on QLabel?

    erm, I don't think you should be using a QLabel for that. Take a look at QPainter. QLabel is for displaying text (or an image)

  3. #3
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can I draw with brush on QLabel?

    Quote Originally Posted by genjix View Post
    erm, I don't think you should be using a QLabel for that. Take a look at QPainter. QLabel is for displaying text (or an image)
    in my programm i use QLabel for displaying an image, and i want to draw on this image (QLabel) with mouse pointer. How can i do it?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How can I draw with brush on QLabel?

    Reimplement paint event and mouse events for the widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How can I draw with brush on QLabel?

    What is the benefit of creating a QImage and then immediately converting it to a QPixmap?

    For painting: Reimp all needed mouse event handlers and then either using QPainter and draw an the QPixmap or store all lines etc. call update() and do the drawings at the paint event.

    EDIT: Just found out, that my browser has a refresh button. Maybe I should use it from time to time...

Similar Threads

  1. To draw images in QLabel
    By augusbas in forum Qt Programming
    Replies: 5
    Last Post: 11th October 2010, 06:27
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Replies: 6
    Last Post: 21st September 2009, 10:55
  4. something like colordialog, but with brush
    By Noxxik in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2009, 20:22
  5. How can I draw on Qlabel
    By validator in forum Qt Programming
    Replies: 4
    Last Post: 4th August 2008, 08:58

Tags for this Thread

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.