Results 1 to 9 of 9

Thread: Get QImage from QFrame

  1. #1
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Get QImage from QFrame

    Hi,

    How do I get QImage of a QFrame display?

    Thanks in advance.

  2. #2
    Join Date
    Sep 2009
    Posts
    72
    Thanked 10 Times in 10 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Get QImage from QFrame

    I am not sure what you meant by that but if you mean getting image set on QFrame then try QPalette class.

  3. #3
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get QImage from QFrame

    Hi, I'm not setting QImage on QFrame.

    Let me illustrate. There's an example on http://labs.trolltech.com/page/Graphics/Examples page.

    Look at the reflection sample. I want to get the QFrame's QImage so that I can manipulate the reflection. In other words, I would like to get all the QLabel, QCheckBox, etc. inside the QFrame to be reflected.

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get QImage from QFrame

    use QPixmap::grabWindow(QFrame)

    or refer Desktop/screenshot example
    "Behind every great fortune lies a crime" - Balzac

  5. The following user says thank you to wagmare for this useful post:

    sheeeng (25th January 2010)

  6. #5
    Join Date
    Sep 2009
    Posts
    72
    Thanked 10 Times in 10 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Get QImage from QFrame

    ok now i got it. ok then u can use QPixmap::grabWidget() method.

    This method will give u entire widget (in you case QFrame) as a pixmap that includes child as well.

  7. The following user says thank you to vishwajeet.dusane for this useful post:

    sheeeng (25th January 2010)

  8. #6
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get QImage from QFrame

    Hi everyone,

    Thanks for showing to use the QPixmap::grabWidget(QWidget*) method.

  9. #7
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get QImage from QFrame

    But the reflection also copies the widget background color.

    How can I use transparency for the QPixmap?

  10. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get QImage from QFrame

    Did you have a look at the code ? The source code is available for that example .
    hers the function for mirrorImage... You can also search for the source code on svn or git.
    Qt Code:
    1. enum FadeStyle {
    2. NoFade,
    3. FadeDown,
    4. FadeRight,
    5. FadeUp,
    6. FadeLeft
    7. };
    8.  
    9. enum MirrorStyle {
    10. NoMirror,
    11. MirrorOverX,
    12. MirrorOverY
    13. };
    14. static inline QImage mirrorImage(const QImage &img, MirrorStyle mirrorStyle=MirrorOverX,
    15. FadeStyle fadeStyle=FadeDown)
    16. {
    17. QImage tmpImage = img;
    18. if (mirrorStyle != NoMirror)
    19. tmpImage = tmpImage.mirrored(mirrorStyle == MirrorOverY,
    20. mirrorStyle == MirrorOverX);
    21.  
    22. if (fadeStyle != NoFade) {
    23. QPoint p1, p2;
    24.  
    25. if (fadeStyle == FadeDown)
    26. p2.setY(tmpImage.height());
    27. else if (fadeStyle == FadeUp)
    28. p1.setY(tmpImage.height());
    29. else if (fadeStyle == FadeRight)
    30. p2.setX(tmpImage.width());
    31. else if (fadeStyle == FadeLeft)
    32. p1.setX(tmpImage.width());
    33.  
    34. QLinearGradient gradient(p1, p2);
    35. gradient.setColorAt(0, Qt::white);
    36. gradient.setColorAt(0.25, QColor(0, 0, 0, 20));
    37. gradient.setColorAt(1, Qt::transparent);
    38.  
    39. QPainter p(&tmpImage);
    40. p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    41. p.fillRect(0, 0, tmpImage.width(), tmpImage.height(), gradient);
    42. p.end();
    43. }
    44. return tmpImage;
    45. }
    To copy to clipboard, switch view to plain text mode 

  11. #9
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get QImage from QFrame

    Hi,

    Thanks for all the advices.

    I manage to get the transparency working by using an heuristic mask and set it to the image.

Similar Threads

  1. Custom QFrame
    By fruzzo in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2009, 14:49
  2. show Qframe
    By peace_comp in forum Qt Programming
    Replies: 2
    Last Post: 17th June 2008, 14:45
  3. a tight QFrame is all i need
    By baray98 in forum Qt Programming
    Replies: 5
    Last Post: 7th January 2008, 07:53
  4. Reg - QFrame
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2006, 04:34
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

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.