Results 1 to 1 of 1

Thread: problem QGLwidget responding clicking

  1. #1
    Join Date
    May 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem QGLwidget responding clicking

    I added a VerticalLayout(600px*600px) in UI ,

    adding it via these code:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    2. {
    3. ui->setupUi(this);
    4. w = new RenjuWidget();
    5. QRect r(0,0,600,600);
    6. ui->verticalLayout->setGeometry(r);
    7. ui->verticalLayout->addWidget(w); //this adds the widget
    8. this->move(0,0);
    9. }
    To copy to clipboard, switch view to plain text mode 

    my widget code is :
    Qt Code:
    1. class RenjuWidget : public QGLWidget
    2. {
    3.  
    4.  
    5. Q_OBJECT
    6.  
    7.  
    8. public:
    9.  
    10.  
    11. RenjuWidget( QWidget * parent = 0 );
    12. ~RenjuWidget();
    13.  
    14.  
    15. protected:
    16.  
    17.  
    18. int posx, posy;
    19.  
    20.  
    21. void initializeGL();
    22. void paintGL();
    23. void resizeGL(int width, int height);
    24.  
    25.  
    26. void keyPressEvent( QKeyEvent *e );
    27. void mousePressEvent(QMouseEvent *e);
    28. };
    To copy to clipboard, switch view to plain text mode 

    my mouse click responding function is:
    Qt Code:
    1. void RenjuWidget::mousePressEvent(QMouseEvent *e)
    2. {
    3. if(e->button() == Qt::LeftButton)
    4. {
    5. posx = e->x();
    6. posy = e->y();
    7. cout<<posx<<"\t"<<posy<<endl;
    8. paintGL();
    9. //QMessageBox::information(NULL,QString("%1").arg(posx),QString("%1").arg(posy),QMessageBox::Ok,QMessageBox::NoButton);
    10. //if I use messagebox , the problem doesn't appear
    11. return ;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    draw function is to draw a triangle on the left side if you click on the left half or a square on the right side if you clicked on the right half.
    Qt Code:
    1. void RenjuWidget::paintGL()
    2. {
    3. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    4. glLoadIdentity();
    5.  
    6.  
    7. if(posx < 300)
    8. {
    9. glTranslatef( -1.5, 0.0, -10.0 );
    10.  
    11.  
    12. glBegin( GL_TRIANGLES );
    13. glColor3f( 1.0, 0.0, 0.0 );
    14. glVertex3f( 0.0, 1.0, 0.0 );
    15. glColor3f( 0.0, 1.0, 0.0 );
    16. glVertex3f( -1.0, -1.0, 0.0 );
    17. glColor3f( 0.0, 0.0, 1.0 );
    18. glVertex3f( 1.0, -1.0, 0.0 );
    19. glEnd();
    20. }
    21.  
    22.  
    23. if(posx > 300)
    24. {
    25. glTranslatef( 1.5, 0.0, -10.0 );
    26.  
    27.  
    28. glBegin( GL_QUADS );
    29. glColor3f(1.0 , 0.0 , 0.0);
    30. glVertex3f( -1.0, 1.0, 0.0 );
    31. glColor3f(0.0 , 1.0 , 0.0);
    32. glVertex3f( 1.0, 1.0, 0.0 );
    33. glColor3f(0.0 , 0.0 , 1.0);
    34. glVertex3f( 1.0, -1.0, 0.0 );
    35. glColor3f(1.0 , 1.0 , 1.0);
    36. glVertex3f( -1.0, -1.0, 0.0 );
    37. glEnd();
    38. }
    39.  
    40.  
    41. glLoadIdentity();
    42. }
    To copy to clipboard, switch view to plain text mode 

    but here comes the problem :

    the picture didn't change after i clicked on it , it has to lost focus and get foucus again to redraw the picture

    for example : I clicked on the left part of the widget , but it doesn't change , if i click on the desktop(or another window) , it changes immediately.

    so why?


    Added after 12 minutes:


    OKAY……I get it solved....

    I have to add "update();" in the mouse clicking function.
    Last edited by gch0214; 21st May 2012 at 07:24.

Similar Threads

  1. QProgressDialogButton is not responding
    By gowen in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2011, 19:13
  2. Clicking Instance problem..
    By anshumanBorah in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2011, 15:24
  3. USB Keyboard is not responding in qt-embedded-4.4.3
    By grsandeep85 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 7th April 2011, 03:13
  4. Designer not responding to mouse
    By brtip in forum Newbie
    Replies: 0
    Last Post: 28th July 2010, 05:09
  5. Window not responding
    By markcole in forum Qt Programming
    Replies: 10
    Last Post: 18th April 2007, 21:53

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.