Results 1 to 9 of 9

Thread: DrawLine over QPixmap within Qlabel

  1. #1
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default DrawLine over QPixmap within Qlabel

    Hello all,


    I Have one Qlabel in which I m displaying one .PNG image using QPixmap.

    Now my program needs to draw few horizontal lines over this image..

    How to add it?????

  2. #2
    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: DrawLine over QPixmap within Qlabel

    Hi, subclass QLabel and reimplemented QWidget::paintEvent ( QPaintEvent * event ). First pas the event to QLabel and then draw your lines using QPainter p(this);

    Lykurg

    EDIT: you also could modify your picture since QPixmap is a QPaintDevice. QPainter p(*yourPixmap);

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DrawLine over QPixmap within Qlabel

    or if you don't want to sublcass QLabel you can install event filter on your label and process QPainEvent.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DrawLine over QPixmap within Qlabel

    Hey could you please show me some code how to do this stuff??????

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DrawLine over QPixmap within Qlabel

    try this
    Qt Code:
    1. QPainter painter(&p);
    2. QLineF line(10.0, 80.0, 90.0, 20.0);
    3. painter.drawLine(line);
    4. label->setPixmap(p);
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    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: DrawLine over QPixmap within Qlabel

    Qt Code:
    1. QPixmap pix(":/your/fancy/png/here");
    2. QPainter p(&pix);
    3. p->drawLine(pix.rect().topLeft(),pix.rect().bottomRight());
    4. //use pix normaly...
    To copy to clipboard, switch view to plain text mode 

  7. #7
    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: DrawLine over QPixmap within Qlabel

    Ok, I am out. spirit you get me one more time...

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DrawLine over QPixmap within Qlabel

    Quote Originally Posted by Lykurg View Post
    Ok, I am out. spirit you get me one more time...
    sorry
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: DrawLine over QPixmap within Qlabel

    Hey thanx both of you,

    Its working now !!!!!!!!!!

Similar Threads

  1. Rotate QPixmap set on QLabel
    By Qt Coder in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2009, 13:08
  2. Replies: 2
    Last Post: 20th January 2009, 08:13
  3. Replies: 3
    Last Post: 17th July 2008, 08:43
  4. paintEvent, QString to QPixmap, QLabel
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2007, 14:04
  5. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 17:24

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.