Results 1 to 5 of 5

Thread: How to draw lines above a frame with background image

  1. #1
    Join Date
    Jul 2011
    Posts
    81
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default How to draw lines above a frame with background image

    I am newto Qt so i want to know about how to draw lines above a frame with background image with Qpainter. when i use painter(this) it draw over the main window which is hidden by the frame with background images. how can i overcome that. when i use painter(ui->frame) it doesnot work. pls help.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to draw lines above a frame with background image

    Looks like you are trying to paint on a QFrame from outside the QFrame:aintEvent(), this is not a good way to do, but may work (depends on from where and how you paint)
    when i use painter(ui->frame) it doesnot work. pls help.
    This should work, what you you mean by does not work, does it draw at all, where does it draw? also from where you paint. (as it look you are not painting from QFrame:aintEvent())

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to draw lines above a frame with background image

    This is third thread started on the same issue, apparently full working code (posted here) is not enough for you. I guess anything written here goes to /dev/null anyway ...

  4. #4
    Join Date
    Jul 2011
    Posts
    81
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: How to draw lines above a frame with background image

    Qt Code:
    1. void mainwindow::paintEvent(QPaintEvent *e)
    2. {
    3. QPainter painter(this);
    4. QPen linepen(Qt::red);
    5. linepen.setCapStyle(Qt::RoundCap);
    6. linepen.setWidth(30);
    7. painter.setRenderHint(QPainter::Antialiasing,true);
    8. painter.setPen(linepen);
    9. if(y==1)
    10. painter.drawPoint(point);
    11. else
    12. painter.drawLine(point,point2);
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    I used this code. for painter(this) i tryed painter(ui->frame3).
    ( i have 3frames for equal size, i use..
    Qt Code:
    1. ui->frame1->hide();ui->frame2->hide();ui->frame3->show();
    To copy to clipboard, switch view to plain text mode 
    to show each frame using button click.
    I have to draw only on the third frame. This code draws on the mainwindow ui window

  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to draw lines above a frame with background image

    RTFM.
    Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.
    If you want to use QPainter on a widget, you can do that ONLY from it's paintEvent. This implies the following - if you want to draw something on a widget, you have to create a subclass. End of story. You can't draw on a widget from some other widget paintEvent, and this is what you are trying to do the whole time.

Similar Threads

  1. How to add lines to desired frame only
    By athulms in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2011, 08:43
  2. Replies: 1
    Last Post: 25th June 2010, 18:31
  3. Draw lines in a QGridLayout
    By Eos Pengwern in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2010, 01:27
  4. how to draw lines on image using QGraphicsView in Qt4
    By madhavilatha in forum What's New in Qt 4.4
    Replies: 1
    Last Post: 25th July 2008, 00:32

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.