Results 1 to 17 of 17

Thread: Unable to set the view port for graphicsview

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Posts
    48
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Unable to set the view port for graphicsview

    Hi,

    If I am using setviewport for the graphicsview , I am getting a transparent screen .

    view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));

    Can anyone please suggest any solution?


    Thanks

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unable to set the view port for graphicsview

    Qt Code:
    1. MainWindow::MainWindow( QWidget *parent ):
    2. QMainWindow( parent )
    3. {
    4. GraphicsView *view = new GraphicsView;
    5. view->setViewport( new QGLWidget( QGLFormat( QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba ) ) );
    6. view->setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
    7. view->setScene( new OpenGLScene );
    8.  
    9. resize( 320, 240 );
    10. setCentralWidget( view );
    11. }
    12.  
    13. GraphicsView::GraphicsView()
    14. {
    15. }
    16.  
    17. void GraphicsView::resizeEvent( QResizeEvent *e )
    18. {
    19. if (scene())
    20. scene()->setSceneRect( QRect( QPoint( 0, 0 ), e->size() ) );
    21.  
    22. QGraphicsView::resizeEvent(e);
    23. }
    24.  
    25. OpenGLScene::OpenGLScene()
    26. {
    27. }
    28.  
    29. OpenGLScene::~OpenGLScene()
    30. {
    31. }
    32.  
    33. void OpenGLScene::drawBackground( QPainter */*painter*/, const QRectF &/*rect*/ )
    34. {
    35. glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
    36. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    37.  
    38. glMatrixMode( GL_PROJECTION );
    39.  
    40. glPushMatrix();
    41. glLoadIdentity();
    42. glViewport( 0, 0, int( width() ), int( height() ) );
    43. //glOrtho( -width() / 2.0, width() / 2.0, -height() / 2.0, height() / 2.0, -1.0, 1000.0 );
    44. glOrtho( 0.0, width(), height(), 0.0, -1.0, 1000.0 );
    45.  
    46. glMatrixMode( GL_MODELVIEW );
    47. glPushMatrix();
    48. glLoadIdentity();
    49. // DRAW HERE
    50. glPopMatrix();
    51. glPopMatrix();
    52.  
    53. //QTimer::singleShot( 1, this, SLOT(update()) );
    54. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QWidget + QGraphicsView + OenGL view port
    By medved6 in forum Qt Programming
    Replies: 5
    Last Post: 30th March 2011, 07:55
  2. How to switch view in sliding/moving new view from right of device to the left
    By curiouswalker in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 16th November 2010, 11:55
  3. Unable to view images in an application created for Windows ce
    By mistertwister in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 4th March 2010, 19:23
  4. Graphicsview??
    By Screeze in forum Newbie
    Replies: 2
    Last Post: 5th July 2009, 17:01
  5. Replies: 5
    Last Post: 21st November 2007, 20:38

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.