Results 1 to 4 of 4

Thread: how to draw outside paintevent?

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

    Default how to draw outside paintevent?

    Qt Code:
    1. void MainWindow::mousePressEvent(QMouseEvent *e)
    2. {
    3. point=e->pos();
    4. setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    5. QPainter painter(ui->frame);
    6. QPen linepen(Qt::red);
    7. linepen.setCapStyle(Qt::RoundCap);
    8. linepen.setWidth(30);
    9. painter.setRenderHint(QPainter::Antialiasing,true);
    10. painter.setPen(linepen);
    11. painter.drawPoint(point);
    12. }
    To copy to clipboard, switch view to plain text mode 


    I used this code but it doesnt work

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: how to draw outside paintevent?

    You normally should not need this, and you normally should not do this.
    There is a way, but probably you don't need it.
    Maybe if you explain why and what you are trying to do, we can show you how to do it the proper way.
    Why don't you just put that drawing code in to the paintEvent()?
    You can simply set a flag in the mousePressEvent() and evaluate that flag in your painEvent() and paint it only if the flag is set, for example.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: how to draw outside paintevent?

    i got the code
    Qt Code:
    1. void MainWindow::mousePressEvent(QMouseEvent *e)
    2. {
    3. point=e->pos();
    4. update();
    5. }
    6. void MainWindow::paintEvent(QPaintEvent *e)
    7. {
    8. setAttribute(Qt::WA_OpaquePaintEvent);
    9. QPainter painter(this);
    10. QPen linepen(Qt::red);
    11. linepen.setCapStyle(Qt::RoundCap);
    12. linepen.setWidth(30);
    13. painter.setRenderHint(QPainter::Antialiasing,true);
    14. painter.setPen(linepen);
    15. painter.drawPoint(point);
    16. }
    To copy to clipboard, switch view to plain text mode 

    it worked for me

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

    Default Re: how to draw outside paintevent?

    You shouldn't use OpaquePaintEvent in this situation. And certainly you shouldn't set the flag in the paint event.
    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.


Similar Threads

  1. qt paintEvent
    By lzpmail in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2011, 14:13
  2. Replies: 10
    Last Post: 11th February 2011, 00:31
  3. paintEvent help
    By seltra in forum Newbie
    Replies: 11
    Last Post: 18th September 2010, 20:24
  4. Replies: 3
    Last Post: 27th August 2010, 07:00
  5. Finish of PaintEvent
    By jimfan in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 08:50

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
  •  
Qt is a trademark of The Qt Company.