Results 1 to 17 of 17

Thread: Printing a QGLWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 8 Times in 4 Posts

    Default Re: Printing a QGLWidget

    What I mean by a child in this instance is I have one object (class) that is derived from the QGLWidget class. This QGLWidget is my plot object I then have other objects of different classes that all have a pointer to my QGLWidget object (the plot). So if I want to have grid lines I create a grid line object and allow it access to my plot object so it can draw directly onto the QGLWidget. This grid line object is what I mean when I say a child object. So the data line object and titles object are also examples of what I mean by a child. Sorry I guess child is the wrong word to use, but they all look up to the main plot object like a parent-figure thus being why I called them children. All of these children or sub-objects are all QObjects so they can render onto the QGLWidget. All of these sub-QObjects have a paint function which is called inside the plot object's paintGL function.

    I do not know anything about this QGLContext stuff as I have not used it. I might look into this, but I do not know if I need to handle anything with this. I have not retrieved any contexts anywhere but everything draws correctly on the screen. Is there anything else you need to know? What code do you mean you want when you say just the beginning and ending parts? Thanks again!

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

    Default Re: Printing a QGLWidget

    Quote Originally Posted by ToddAtWSU View Post
    I do not know anything about this QGLContext stuff as I have not used it.
    You have used it but Qt managed it for you behind the scene.

    I might look into this, but I do not know if I need to handle anything with this.
    Yes, you do if you want to render to a pixmap.

    I have not retrieved any contexts anywhere but everything draws correctly on the screen.
    Because you were using a single context (the GLWidget viewport). If you want to render to a pixmap, Qt creates a temporary context for you and uses it to do the rendering. Look at a fragment of QGLWidget::renderPixmap() docs:
    This method will create a pixmap and a temporary QGLContext to render on the pixmap. It will then call initializeGL(), resizeGL(), and paintGL() on this context. Finally, the widget's original GL context is restored.
    Is there anything else you need to know? What code do you mean you want when you say just the beginning and ending parts? Thanks again!
    I think that in this situation and with your design you won't be able to render to a pixmap. It is possible that grabWidget() uses renderPixmap() as well, which would explain why you get the same result. You need to change your design so that a chain of initializeGL() - resizeGL() - paintGL() calls can result in a valid render (without any need to call any additional methods). Your painting subroutines should handle the context switching - it's all explained in the docs (QGLWidget):

    Your widget's OpenGL rendering context is made current when paintGL(), resizeGL(), or initializeGL() is called. If you need to call the standard OpenGL API functions from other places (e.g. in your widget's constructor or in your own paint functions), you must call makeCurrent() first.
    I don't know how you implemented your paint methods, but it is possible that you're explicitely rendering to the widget's context instead of the pixmap context. That's why I asked you to post a sample painting routine.

  3. #3
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 8 Times in 4 Posts

    Default Re: Printing a QGLWidget

    I decided to change my plot background to white and now when I save to a file I see everything else. But everything else is drawn in black instead of the color it should be. It appears that this capturing is only working in black and white. I am using a QGLColormap and using glIndexi( ) to state my colors from the colormap. So I am wondering if this is causing the problem as to why the color is not being captured. We are trying to use 8-bit color and I am wondering if this tries to convert it to 24-bit color before printing/saving it and if it loses its color in the translation. I will look more into this, but if you think you have an idea why the color would be getting lost, I would love to hear it. Thanks!

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

    Default Re: Printing a QGLWidget

    Colours shouldn't get lost by converting from a more strict to a less strict colour model, so I doubt that's the case.

  5. #5
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 8 Times in 4 Posts

    Default Re: Printing a QGLWidget

    I took a little break from this printing item but am now back at it. I got to thinking over the weekend, I am using a colormap for my plot. Could this be the reason I am not capturing the colors? The pixmap that I am creating from my QGLWidget does not know how to associate the colors with the colors stored in my Colormap. My colormap is not referenced off a QGLColormap however. So is there a way to set a colormap for my pixmap to help it capture the colors that are really supposed to be there. All I still get is a black and white image. Thanks again for your help!!!

  6. #6
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 8 Times in 4 Posts

    Default Re: Printing a QGLWidget

    I found that QImage has a color table so I printed out its size and values. It said its color table was size 17 and all of its colors were either black or white. So I am in the process of changing the color table to match my color map. Unfortunately, my colormap is only 15 colors large, and if I try to change the color table to be only 15 colors big, it crashes because of trying to index beyond its range. Do you have any idea what I can do to get it to only use the 15 colors because I have no idea what to make the extra 2 colors, should they be black or white or what? Thanks again for all your help!

Similar Threads

  1. QGLWidget renderText rotation
    By ToddAtWSU in forum Qt Programming
    Replies: 4
    Last Post: 19th September 2007, 20:52
  2. QGLWidget on another QGLWiget
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2006, 09:59
  3. QGLWidget Problems
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2006, 22:06
  4. Replies: 0
    Last Post: 28th June 2006, 20:49

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.