Results 1 to 13 of 13

Thread: grabWidget

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default grabWidget

    Hi,
    I need to grab only my QGLWidget. but grabWidget take only QWidget?
    This below grab only a gray square!
    Qt Code:
    1. QPixmap qp = QPixmap::grabWidget(myGLWidget, 0,0, -1, -1);
    To copy to clipboard, switch view to plain text mode 
    Is there a way or I must use grabWindow?
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabWidget

    Use QGLWidget::renderPixmap().

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabWidget

    the problem of this function is that (I read) will start initalizeGL, paintGL() etc...and after this call my contextGL() changes! There are some problem. I don't know if are there ways to avoid this...

    I tried use grabWindow.it grab all widget are on my interest widget But very problem of this is that it grab also a QMessageBox::warning that is launched a bit before of grabbing. How can I avoid this?

    Thanks
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabWidget

    Quote Originally Posted by mickey
    the problem of this function is that (I read) will start initalizeGL, paintGL() etc...and after this call my contextGL() changes! There are some problem. I don't know if are there ways to avoid this...
    Why do you want avoid this? If you implement these methods properly you shouldn't have any problems.

    Quote Originally Posted by mickey
    I tried use grabWindow.it grab all widget are on my interest widget But very problem of this is that it grab also a QMessageBox::warning that is launched a bit before of grabbing. How can I avoid this?
    In Qt3 QGLWidget bypasses the Qt painting engine, so you must use QGLWidget::renderPixmap(). You can also try to make a screenshot.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabWidget

    Quote Originally Posted by jacek
    Why do you want avoid this? If you implement these methods properly you shouldn't have any problems.
    my texture are destroyed after renderPixmap! If I use grabWindow this not happen.....
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabWidget

    Quote Originally Posted by mickey
    my texture are destroyed after renderPixmap! If I use grabWindow this not happen.....
    How do you initialize those textures?

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabWidget

    yes, in initalializeGL()
    Regards

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabWidget

    Quote Originally Posted by mickey
    yes, in initalializeGL()
    But how do you initialize those textures?

  9. #9
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabWidget

    Qt Code:
    1. //initializeGL()
    2. per.myinitGL();
    3. glEnable(GL_TEXTURE_2D);
    4. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    5. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    6. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    7. glDisable(GL_TEXTURE_2D);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. perc::myInitGL() {
    2. glGenTextures(1, &tex);
    3. QImage img;
    4. if ( !img.load(texFileName)) {
    5. QImage buf;
    6. buf.fill(Qt::gray.rgb() );
    7. img=buf;
    8. }
    9. QImage tx = QGLWidget::convertToGLFormat (img);
    10. glBindTexture(GL_TEXTURE_2D, tex);
    11. gluBuild2DMipmaps(GL_TEXTURE_2D, 3, tx.width(), tx.height(), GL_RGBA, GL_UNSIGNED_BYTE, tx.bits() );
    12. }
    To copy to clipboard, switch view to plain text mode 
    Is it ok? It seems works properly....
    Regards

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabWidget

    Quote Originally Posted by mickey
    Is it ok? It seems works properly....
    Every time initializeGL() is called, per.myinitGL() will overwrite the tex variable. Maybe it will be enough, if you check whether initializeGL() is called for the first time and only then call per.myinitGL()?

    What is that "per" object?

  11. #11
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabWidget

    'per' is my object on I put texture...a square; Are you saying me that when I call renderpixmap(), initializeGL() starts and tex is overwrite? (But tex should be the same before......).
    But what is the advantage for renderPixmap() of re-call initializeGL and PaintGL()? Isn't it a time lose?
    Regards

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabWidget

    QPixmap QGLWidget::renderPixmap ( int w = 0, int h = 0, bool useContext = FALSE ) [virtual]
    Renders the current scene on a pixmap and returns the pixmap.
    [...]
    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.
    [...]
    If useContext is TRUE, this method will try to be more efficient by using the existing GL context to render the pixmap. The default is FALSE. Only use TRUE if you understand the risks.
    Overlays are not rendered onto the pixmap.
    If the GL rendering context and the desktop have different bit depths, the result will most likely look surprising.
    Note that the creation of display lists, modifications of the view frustum etc. should be done from within initializeGL(). If this is not done, the temporary QGLContext will not be initialized properly, and the rendered pixmap may be incomplete/corrupted.
    Your initializeGL() must be written in such way that it can be called multiple times and you must make sure that after renderPixmap() you restore the previous state. For example if you create textures in initializeGL() then after renderPixmap() you should use old texture ids.

    You can also try to reuse the constext (see the docs), but pixmap may have a different colour depth than the screen.

  13. #13
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabWidget

    Hi, the problem wasn't renderPixmap() ( that calls initializeGL() and paintGL().
    renderPixmap() starts when I save my scene; it works properly if I simple save (without open saveDialogFile). If saveDialogFile starts and I click 'ok' button my contextGL broke;
    It's strange.....
    Regards

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.