Results 1 to 2 of 2

Thread: Setting border for QGLWidget derived object

  1. #1
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Setting border for QGLWidget derived object

    Hi to all Qt forum members. I'm new to this forum. I have been learning Qt 4 and programming a GUI application for my project for about a few months now.

    Now I have this QGLWidget derived object which I want to paint its border to different color when it receive or lose focus. I have successfully detect the focus change events by reimplement the focusInEvent and focusOutEvent functions but now I'm stuck at setting the border style.

    Apparently setStyleSheet doesn't work for QGLWidget. The following is my code for implementing this feature:

    Qt Code:
    1. void myGLWidget::focusInEvent( QFocusEvent * event )
    2. {
    3. QGLWidget::focusInEvent(event);
    4.  
    5. if(event->gotFocus())
    6. {
    7. //Set a highlight border
    8. this->setStyleSheet("border: 1px solid white");
    9. }
    10.  
    11.  
    12. }
    13.  
    14. void myGLWidget::focusOutEvent( QFocusEvent * event )
    15. {
    16. QGLWidget::focusOutEvent(event);
    17.  
    18. if(event->lostFocus())
    19. {
    20. //Set the non focus border
    21. this->setStyleSheet("");
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    The border of myGLWidget doesn't change whether I select it or not.

    I did set the setFocusPolicy(Qt::StrongFocus) function and also implemented some interactive controls on myGLWidget so I am pretty sure it is selectable.

    I tried to look for answers elsewhere but to no avail. Can anyone here help me?

  2. #2
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting border for QGLWidget derived object

    I manage to solve the problem by using OpenGL to draw the viewport borders using Ortho projection instead of Widget style. Still it seems more correct to draw using Widget style. Is there a way to draw the border of OGLWidget-derived widget using Widget style?

Similar Threads

  1. Can't add an object derived from QWidget in a layout.
    By Netich in forum Qt Programming
    Replies: 1
    Last Post: 14th January 2010, 22:55
  2. Replies: 1
    Last Post: 21st August 2008, 08:44
  3. Setting window icon on derived QWidget
    By steg90 in forum Qt Programming
    Replies: 5
    Last Post: 16th July 2007, 12:21
  4. Can't compile custom class derived from QGLWidget
    By stealth86 in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2007, 18:55
  5. How to call QValidator derived object
    By bruccutler in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2007, 18:07

Tags for this Thread

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.