Results 1 to 12 of 12

Thread: Saving the widget class as a QPixmap

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Saving the widget class as a QPixmap

    Hi,

    I have a class foo in which I created two QGraphicsLineItem and one QGraphicsEllipseItem. Together they form a different composite shape in foo. What I want to do is saving this shape as a QPixmap! OR transfering this whole shape into a QPixmap. Is it possible it QT?

    Regards
    Last edited by zgulser; 30th January 2009 at 18:46.

  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: Saving the widget class as a QPixmap


  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Saving the widget class as a QPixmap

    Hi again,

    Is there any idea?

    Regards

  4. #4
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Saving the widget class as a QPixmap

    Hi,

    I don't want to render. I guess I mistold my problem.

    I want to convert my class, which I draw s shape in it, into a QPixmap OR,
    to put my shape into a QPixmap.

    Is that what you understood?

    Regards

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Saving the widget class as a QPixmap

    Oh sorry, I just understood what did you say.


    Hımm does it work for QPainter painter(&QPixmap_object) ?

    OR grabWidget could do the same thing?

    Regards

  6. #6
    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: Saving the widget class as a QPixmap

    Oh boy... is it so hard to read 2-3 paragraphs of the documentation?

    Qt Code:
    1. QPixmap myPixmap(600,400);
    2. myPixmap.fill(Qt::white); // unless you want transparent background
    3. QPainter p(&myPixmap);
    4. myScene->render(&p);
    5. p.end();
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Saving the widget class as a QPixmap

    Hi,

    Yes yes, I sad I'am sorry, I didn't recognize what's written there for a moment cuz I'am really overloaded. Sorry again.

    One more; scene.render(&p) makes the scene a QPixmap? cuz, it's return type is void.

    By the way, what do you say about grabWidget?

    Regards
    Last edited by zgulser; 30th January 2009 at 21:47.

  8. #8
    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: Saving the widget class as a QPixmap

    Quote Originally Posted by zgulser View Post
    One more; scene.render(&p) makes the scene a QPixmap? cuz, it's return type is void.
    Think why it takes a pointer to the painter object and what it might do with it.

    By the way, what do you say about grabWidget?
    I say it is not for you because it would contain not only the contents of the view but also the frame of the view. Please use QScene::render() as suggested.

  9. #9
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Saving the widget class as a QPixmap

    Hi,

    I converted my widget to QPixmap by following the instructions that you provided, but now the widget did not fit with the QPixmap. I mean only some part of the widget can be seen on the pixmap.


    Regards

  10. #10
    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: Saving the widget class as a QPixmap

    So make the pixmap bigger.

  11. #11
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Saving the widget class as a QPixmap

    Yes, I did and it works OK.

    I checked but didn't find how to put my widget at the middle of the pixmap. I mean I want to control the coordinates of my pixmap. By biggering the pixmap, I couldn't get the true sense of such controling since the most of the pixmap field is empty.

    Thanks again wysota

    Regards

  12. #12
    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: Saving the widget class as a QPixmap

    Have you tried actually reading the documentation of classes and methods before using them? Have you seen the docs of QGraphicsScene::render()?

Similar Threads

  1. Replies: 3
    Last Post: 27th December 2008, 19:34
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  4. making a class aware of the gui
    By aegis in forum Qt Programming
    Replies: 10
    Last Post: 2nd April 2007, 23:56
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

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.