Results 1 to 5 of 5

Thread: Drawing widgets inside a Qt application

  1. #1
    Join Date
    May 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Drawing widgets inside a Qt application

    I've seen Qt widgets embedded into a QGraphicsView. What I'd like to do is draw QWidgets inside a OpenGL application.

    In general, the code will setup the OpenGL scene and transformations, then ask a widget to paint itself using OpenGL. I know there are OpenGL paint engines, I just don't know how to setup the painting devices to have the widget paint inside of a larger OpenGL app.

    In practice, this could be done inside of a QGLWidget. In the paintGL routine, it'll do the opengl calls it needs, and at the appropriate time, setup a opengl paint engine and draw the widget, then finish the GL drawing.

    Can someone tell me if this is something I can do?

    John

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drawing widgets inside a Qt application

    You should create a graphics view with OpenGL viewport (see QGraphicsView::setViewport() - set a QGLWidget as the viewport). Then you will be able to place widgets inside the scene and they will be rendered using OpenGL calls. At the same time you can use OpenGL calls to render i.e. the background of your scene (drawBackground()).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing widgets inside a Qt application

    That's not quite what I'm looking for. I don't want to use QGraphicsViews, I want a widget to draw itself, on command, using the OpenGL calls. It'd be something like this....

    void MyObj:aintGL() {
    // setup gl matrices

    // do other GL painting stuff

    QPushButton button("foobar");

    button.paint(within_this_established_openGL_enviro nment);

    // Manipulate the modelview matricies.

    // Draw that same button again transformed just to make a point.
    button.paint(within_this_established_openGL_enviro nment);
    }

    I realize this isn't right, but this is the context in which I want to render widgets.

  4. #4
    Join Date
    Apr 2010
    Location
    Portland, OR
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Drawing widgets inside a Qt application

    Can't comment on OpenGL, but usually I create a QWidget inherited object and overwrite the virtual QWidget:aintEvent(QPaintEvent* event):

    Qt Code:
    1. void MyWidget::paintEvent(QPaintEvent* event)
    2. {
    3. QPainter painter(this);
    4. // use painter to draw
    5. }
    To copy to clipboard, switch view to plain text mode 
    Then I place it into an empty QFrame object of the parent window.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drawing widgets inside a Qt application

    Quote Originally Posted by aughey View Post
    I don't want to use QGraphicsViews, I want a widget to draw itself, on command, using the OpenGL calls.
    And what is wrong with using Graphics View for that?

    If you just want the looks of a button, then you can render a button to an image (either directly using a widget or through QStyle) and then use that as a texture in OpenGL. But the widget will not be clickable, etc. For that you need Graphics View.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Drawing QImage inside QTextDocument
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 07:52
  2. Widgets inside ListWidget ?
    By drake1983 in forum Newbie
    Replies: 1
    Last Post: 18th April 2008, 16:45
  3. Replies: 2
    Last Post: 17th March 2008, 23:49
  4. QT 4.2.3 Using GTK Widgets inside QT App
    By chuckshaw in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2007, 03:40
  5. Drawing over content widgets? (overlay)
    By sertrem in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 22:18

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.