Results 1 to 4 of 4

Thread: how to draw a rectangle on an image label without overloading paintEvent function

  1. #1
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default how to draw a rectangle on an image label without overloading paintEvent function

    i want to draw a rectangle on an image label without overloading paintEvent function......... I don't want to use paintEvent b'coz i have to pas the name of the image to be displayed(frameName) each time I display an image out of a series of images.
    Earlier I had drawn suing the following code in the paintEvent function.Now how should I do it without using the paintEvent function.

    Qt Code:
    1. if((i >= startFrameMarkerPosition)&&(i < endFrameMarkerPosition))
    2. {
    3. painter.drawPixmap(0,0,QPixmap(localFileName.at(i)));
    4.  
    5. int x,y,w,h;
    6. x=100; y=200; w=TIME_INTERVAL_PROCESSING_PLAY;h=60;
    7. painter.setPen(Qt::red);
    8. painter.drawRect(x,y,w,h);
    9.  
    10. QLabel::paintEvent(event);
    11.  
    12. localSlider->setValue(i);
    13. i++;
    14. }
    To copy to clipboard, switch view to plain text mode 
    Thanx in advance!!

  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: how to draw a rectangle on an image label without overloading paintEvent functio

    You can use QPainter also direct on the image. So draw on the image and set it to your label.

  3. #3
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: how to draw a rectangle on an image label without overloading paintEvent functio

    I have implemented it as:
    Qt Code:
    1. if((i >= startFrameMarkerPosition)&&(i < endFrameMarkerPosition))
    2. {
    3. painter.drawPixmap(0,0,QPixmap(currentFrameName));//When this line //is commented,even then the rectangle drawn below is not displayed.Actually neither of them //is working(the 'drawPixmap' and the 'drawRect')
    4.  
    5. int x,y,w,h;
    6. x=100; y=200; w=80;h=60;
    7. painter.setPen(Qt::red);
    8. painter.drawRect(x,y,w,h);
    9.  
    10. //QLabel::paintEvent(event);
    11.  
    12. localSlider->setValue(i);
    13. i++;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Can you tell me how to draw on an image!
    Last edited by qt_user; 27th August 2010 at 05:55.

  4. #4
    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 draw a rectangle on an image label without overloading paintEvent functio

    Something in the lines of:

    Qt Code:
    1. QPixmap myPixmap(100, 100); // size
    2. QPainter painter(&myPixmap);
    3.  
    4. // Use the painter to draw things
    5.  
    6. // Then use the pixmap like:
    7. myLabel->setPixmap(myPixmap);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. HOW TO DISPLAY A RECTANGLE ON AN IMAGE on a label
    By qt_user in forum Qt Programming
    Replies: 4
    Last Post: 6th August 2010, 15:19
  2. Replies: 1
    Last Post: 30th July 2010, 07:50
  3. How to draw rectangle with moveable edge
    By sagirahmed in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2010, 06:21
  4. how to draw columns in QPainter's rectangle
    By jyoti in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2007, 10:50
  5. Draw a rectangle alternating two colors with qPainter
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 24th January 2006, 23:12

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.