Results 1 to 8 of 8

Thread: Saving a FULLY rendered QWidget on a graphics scene

  1. #1
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Question Saving a FULLY rendered QWidget on a graphics scene

    Hi,

    I have several widgets in a graphics scene. I want to take a image copy of 1 of the widgets.

    I attempted the following:

    Qt Code:
    1. QPixmap screenshot;
    2. screenshot = QPixmap::grabWidget(theWidget,theWidget.rect());
    3. screenshot.save("test.png","PNG");
    To copy to clipboard, switch view to plain text mode 

    THis will save the widget but the widget is stripped of EVERYHTING. Basically you don't see the background image on the widget, you don't see any alpha settings I set, you simply see an outline of the widget and some text.

    I also tried:
    Qt Code:
    1. QImage image(300,300,QImage::Format_RGB32);
    2. QPainter painter(&image);
    3.  
    4. TheGraphicsView->render(&painter);
    5. image.save("test.png","PNG");
    To copy to clipboard, switch view to plain text mode 

    This will give me the exact same result as above.


    Lastly I tried:
    Qt Code:
    1. screenshot = QPixmap::grabWindow(QApplication::desktop()->winId());
    To copy to clipboard, switch view to plain text mode 

    This will capture the whole screen which is not what I wanted. This will though show everyhting fully rendered.

    Any ideas how I can capture just 1 WIDGET in the graphics view fully rendered?

    Thanks

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

    Default Re: Saving a FULLY rendered QWidget on a graphics scene

    Qt Code:
    1. QPixmap px(QRect(QPoint(0,0), theWidget->sceneRect().size());
    2. QPainter painter(&px);
    3. scene->render(&painter, QRectF(), theWidget->sceneRect());
    To copy to clipboard, switch view to plain text mode 
    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. The following user says thank you to wysota for this useful post:

    technoViking (25th October 2010)

  4. #3
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Default Re: Saving a FULLY rendered QWidget on a graphics scene

    Hi thanks for the responce! But QWdiget doesn't have a member sceneRect() it does have a ->rect() function though, is that what you meant?

    Qt Code:
    1. QPixmap px(QRect(QPoint(0,0), mpCalendarWidget->rect().size()));
    2. QPainter painter(&px);
    3. this->escapeGraphicsScene->render(&painter,QRectF(),mpCalendarWidget->rect().size());
    To copy to clipboard, switch view to plain text mode 

    I get an error saying:
    error: no matching function for call to QPixmap::Qpixmap(QRect)

    Another error saying:
    No matching function call to QGraphicsScence::render(QPainter*,QRectF,QSize)

    The error is on the first line, I guess the constructor for QPixmap dosen't support QRect.


    EDIT:
    I changed the code to the following:

    Qt Code:
    1. QPixmap px(mpCalendarWidget->rect().size());
    2. QPainter painter(&px);
    3. this->TheGraphicsScene->render(&painter,QRectF(),mpCalendarWidget->rect());
    4.  
    5. QLabel *mpImageLabel = new QLabel(this);
    6. mpImageLabel->setPixmap(px);
    7. mpImageLabel->show();
    To copy to clipboard, switch view to plain text mode 

    It compiles but when I run the application nothing is shown except a black box in the corner of the screen. Am I doing something wrong?

    Thanks
    Last edited by technoViking; 25th October 2010 at 18:24.

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

    Default Re: Saving a FULLY rendered QWidget on a graphics scene

    Is "mpCalendarWidget" inserted into the scene or is it just some widget floating over the 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.


  6. #5
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Default Re: Saving a FULLY rendered QWidget on a graphics scene

    Hi,

    yes its in the scene, I have code here:

    Qt Code:
    1. GraphicsScene = new QGraphicsScene( QRect( 0, 0, GraphicsView->width(), GraphicsView->height()) );
    2.  
    3. GraphicsView->setScene(GraphicsScene);
    4.  
    5. mpCalendarWidget = new CldrWidget(mpStateMachine);
    6.  
    7. mpCalendarWidgetProxy = GraphicsScene->addWidget(mpCalendarWidget);
    8. mpCalendarWidget->setGeometry((gLCDhres-mpCalendarWidget->width())/2,
    9. mpMainButtonTray->y()-mpCalendarWidget->height(),
    10. mpCalendarWidget->width(),
    11. mpCalendarWidget->height());
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Saving a FULLY rendered QWidget on a graphics scene

    So "mpCalendarWidget" from my code is "mpCalendarWidgetProxy" from yours.
    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.


  8. The following user says thank you to wysota for this useful post:

    technoViking (25th October 2010)

  9. #7
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Default Re: Saving a FULLY rendered QWidget on a graphics scene

    Hi,

    Thanks for the responce! I think we almost got it! But still not able to compile what you gave or perhaps I'm misunderstanding.
    So I attempted:

    Qt Code:
    1. QPixmap px(QRect(QPoint(0,0),mpCalendarWidgetProxy->sceneBoundingRect().size() )); //note: ProxyWidget doesn't have a member called scenceRect so I figured you meant sceneBoundingRect
    2.  
    3. QPainter painter(&px);
    4. this->GraphicsScene->render(&painter,QRectF(),mpCalendarWidgetProxy->sceneBoundingRect()); //note: also used boundingRect here as well since no scenceRect could be found.
    To copy to clipboard, switch view to plain text mode 

    I got the follow error:
    no matching function call to 'QRect::QRect(QPoint,QSizeF)'
    So it looks like this line: QPixmap px(QRect(QPoint(0,0),mpCalendarWidgetProxy->sceneBoundingRect().size() )); is the issue

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

    Default Re: Saving a FULLY rendered QWidget on a graphics scene

    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. Using QLayout for layout in a graphics scene
    By ticica in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2009, 04:07
  2. QWidget setMask fully transparent.
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 6th August 2009, 13:30
  3. graphics scene
    By dognzhe in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2009, 08:55
  4. Buttons in Graphics Scene
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2007, 19:24
  5. QTreeWidget and Graphics scene
    By aamer4yu in forum Qt Programming
    Replies: 7
    Last Post: 21st December 2006, 17:24

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.