Results 1 to 17 of 17

Thread: drawRect inside paintGL()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drawRect inside paintGL()

    Better try creating that painter on the stack every time you need it.

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: drawRect inside paintGL()

    mmm but I need it fixed displayed on myWidgetGL....
    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drawRect inside paintGL()

    Just create the painter on the stack in the method which uses it, this way it will be destroyed in the right time and you won't have to bother with QPainter::end().

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: drawRect inside paintGL()

    Sorry, but how do I create painter on the stack?? But the problem of have fixed rect on my QGLWidget persist....
    Thanks
    Regards

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drawRect inside paintGL()

    Qt Code:
    1. QPainter painter( this );
    2. painter.setPen(QPen(QColor(255,255,255),1,QPen::DotLine));
    3. painter.drawRect(10,10,50,50);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: drawRect inside paintGL()

    sorry but I tried also this (I insert in paintGL() ) but the rect isn't appear; apper only while I traslate/rotate my scene (when updateGL()); maybe is there something that delete it?mmm; (ok for problem of painter.end()). Thanks
    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drawRect inside paintGL()

    Then try:
    Qt Code:
    1. void myWidgetGL::paintEvent( QPaintEvent *event )
    2. {
    3. QGLWidget::paintEvent( event );
    4.  
    5. QPainter painter( this );
    6. painter.setPen(QPen(QColor(255,255,255),1,QPen::DotLine));
    7. painter.drawRect(10,10,50,50);
    8. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: drawRect inside paintGL()

    with your code console ask me this: 'painter.begin(this);' adding this istruction seems works , but when I traslate /rotating my scene square disappear (calls to updateGL() ); strange: if I click on my scene (updateGL occurs) rect appear; I see that If I moveMouse with buttonMouse down paintEvent() not occurs; instead If I click only, paintEvent occur();
    Furthermore I have QWidget::mouseLeave() where inside there's an updateGL(): when I mouse mouse out, updateGL occurs and rect disappear!
    mmmmm....
    Regards

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drawRect inside paintGL()

    It looks like QGLWidget repaints are handled in a special way. You might try rendering your scene to a pixmap, painting on that pixmap and then displaying it, but this will affect the performance.

Similar Threads

  1. paintGL() and initializeGL() help
    By mickey in forum Newbie
    Replies: 14
    Last Post: 26th February 2006, 17:15

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.