Results 1 to 6 of 6

Thread: QRubberBand problem on QGLWidget

  1. #1
    Join Date
    Sep 2010
    Posts
    46
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default QRubberBand problem on QGLWidget

    Hi there,

    We discussed about that couple of days ago, lately i was give up but i have to use that so i wanna share some piece of code ,first of all i made a test project which have QGraphicsView and QGLWidget two of them have same CustomRB implementation QGraphicsView works well but QGLWidget looks like bugly , so there is my code and screenshot :

    Qt Code:
    1. class hsGView : public QGraphicsView
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. hsGView(QWidget *parent = 0);
    7. private :
    8. CustomRB *rubberBand;
    9. QPoint origin;
    10.  
    11. protected:
    12.  
    13. void mousePressEvent(QMouseEvent *event);
    14. void mouseMoveEvent(QMouseEvent *event);
    15. void mouseReleaseEvent(QMouseEvent *event);
    16. };
    17.  
    18. #endif // HSGVIEW_H
    19.  
    20. #include "hsgview.h"
    21.  
    22. hsGView::hsGView(QWidget *parent) : QGraphicsView(parent)
    23. {
    24. rubberBand = new CustomRB(QRubberBand::Rectangle,this);
    25. }
    26.  
    27. void hsGView::mousePressEvent(QMouseEvent *e)
    28. {
    29. origin = e->pos();
    30. rubberBand->setUpdatesEnabled(true);
    31. rubberBand->setGeometry(QRect(origin, QSize()));
    32. rubberBand->show();
    33. }
    34.  
    35. void hsGView::mouseMoveEvent(QMouseEvent *e)
    36. {
    37. rubberBand->setGeometry(QRect(origin, e->pos()).normalized());
    38. update();
    39. }
    40.  
    41. void hsGView::mouseReleaseEvent(QMouseEvent *e)
    42. {
    43. rubberBand->setGeometry(QRect(origin, e->pos()).normalized());
    44. rubberBand->show();
    45. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class HSGLWidget : public QGLWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. HSGLWidget(QWidget *parent = 0);
    7.  
    8. private:
    9. CustomRB *rubberBand;
    10. QPoint origin;
    11.  
    12. protected:
    13.  
    14. void initializeGL();
    15. void resizeGL(int w, int h);
    16.  
    17. void mousePressEvent(QMouseEvent *e);
    18. void mouseMoveEvent(QMouseEvent *e);
    19. void mouseReleaseEvent(QMouseEvent *e);
    20. void keyPressEvent(QKeyEvent *e);
    21. };
    22.  
    23. #include "hsglwidget.h"
    24.  
    25. HSGLWidget::HSGLWidget(QWidget *parent)
    26. :QGLWidget(parent),rubberBand(0)
    27. {
    28. rubberBand = new CustomRB(QRubberBand::Rectangle, this);
    29.  
    30. }
    31.  
    32. void HSGLWidget::initializeGL()
    33. {
    34.  
    35. }
    36.  
    37. void HSGLWidget::resizeGL( int w, int h )
    38. {
    39.  
    40. }
    41.  
    42. void HSGLWidget::mousePressEvent( QMouseEvent *e )
    43. {
    44. origin = e->pos();
    45. rubberBand->setUpdatesEnabled(true);
    46. rubberBand->setGeometry(QRect(origin, QSize()));
    47. rubberBand->show();
    48. }
    49.  
    50. void HSGLWidget::mouseMoveEvent( QMouseEvent *e )
    51. {
    52. rubberBand->setGeometry(QRect(origin, e->pos()).normalized());
    53. update();
    54. }
    55.  
    56. void HSGLWidget::keyPressEvent( QKeyEvent *e )
    57. {
    58.  
    59. }
    60.  
    61. void HSGLWidget::mouseReleaseEvent(QMouseEvent *e)
    62. {
    63. rubberBand->setGeometry(QRect(origin, e->pos()).normalized());
    64. rubberBand->show();
    65. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class CustomRB : public QRubberBand
    2. {
    3. public:
    4. CustomRB(Shape s, QWidget *parent) : QRubberBand(s,parent) {
    5.  
    6. }
    7. protected:
    8.  
    9. void resizeEvent(QResizeEvent *ev)
    10. {
    11. }
    12.  
    13. void paintEvent(QPaintEvent *event)
    14. {
    15. Q_UNUSED(event);
    16. QApplication::processEvents();
    17.  
    18. QPainter painter;
    19. QPen pen = QPen(Qt::yellow);
    20. pen.setWidth(5);
    21. pen.setStyle(Qt::DashLine);
    22.  
    23. QBrush brush = QBrush(Qt::red);
    24.  
    25. painter.begin(this);
    26. painter.setPen(pen);
    27. painter.setOpacity(0.5);
    28. painter.setBrush(brush);
    29. painter.drawRect(event->rect());
    30. painter.end();
    31. }
    32.  
    33. };
    To copy to clipboard, switch view to plain text mode 

    here is the screenshot :

  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: QRubberBand problem on QGLWidget

    It seems to me you GL windget is not doing all it should, but I have little time to look deeper in to this.
    Have a look at this example:
    http://doc.trolltech.com/4.7/opengl-overpainting.html
    ==========================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
    Sep 2010
    Posts
    46
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: QRubberBand problem on QGLWidget

    Thanks again (; high_flyer ,

    I implemented overpainting example to my test project it doesn't make any sense , still flooding RubberBand rectangle :s

  4. #4
    Join Date
    Sep 2010
    Posts
    46
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: QRubberBand problem on QGLWidget

    someone have any idea about that ?

  5. #5
    Join Date
    Sep 2010
    Posts
    46
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: QRubberBand problem on QGLWidget

    any idea ? is it bug or something ?

  6. #6
    Join Date
    Sep 2010
    Posts
    46
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: QRubberBand problem on QGLWidget

    anyone knows, is it bug ?

Similar Threads

  1. QRubberBand problem
    By nightroad in forum Newbie
    Replies: 15
    Last Post: 29th March 2011, 16:11
  2. QGLWidget problem
    By MarkoSan in forum Qt Programming
    Replies: 33
    Last Post: 8th December 2007, 16:50
  3. Serious problem with QGLWidget
    By al101 in forum Qt Programming
    Replies: 12
    Last Post: 27th April 2007, 14:52
  4. Qt3 -> Qt4 QGLWidget::renderText problem
    By cometlinear in forum Qt Programming
    Replies: 6
    Last Post: 1st October 2006, 02:52
  5. QGLWidget renderText problem
    By mbjerkne in forum Qt Programming
    Replies: 1
    Last Post: 7th April 2006, 22:35

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.