PDA

View Full Version : Get QImage from QFrame



sheeeng
25th January 2010, 05:44
Hi,

How do I get QImage of a QFrame display?

Thanks in advance.

vishwajeet.dusane
25th January 2010, 06:21
I am not sure what you meant by that but if you mean getting image set on QFrame then try QPalette class.

sheeeng
25th January 2010, 06:25
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.

wagmare
25th January 2010, 06:28
use QPixmap::grabWindow(QFrame)

or refer Desktop/screenshot example

vishwajeet.dusane
25th January 2010, 06:53
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.

sheeeng
25th January 2010, 06:58
Hi everyone,

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

sheeeng
25th January 2010, 07:02
But the reflection also copies the widget background color.

How can I use transparency for the QPixmap?

aamer4yu
25th January 2010, 09:56
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.


enum FadeStyle {
NoFade,
FadeDown,
FadeRight,
FadeUp,
FadeLeft
};

enum MirrorStyle {
NoMirror,
MirrorOverX,
MirrorOverY
};
static inline QImage mirrorImage(const QImage &img, MirrorStyle mirrorStyle=MirrorOverX,
FadeStyle fadeStyle=FadeDown)
{
QImage tmpImage = img;
if (mirrorStyle != NoMirror)
tmpImage = tmpImage.mirrored(mirrorStyle == MirrorOverY,
mirrorStyle == MirrorOverX);

if (fadeStyle != NoFade) {
QPoint p1, p2;

if (fadeStyle == FadeDown)
p2.setY(tmpImage.height());
else if (fadeStyle == FadeUp)
p1.setY(tmpImage.height());
else if (fadeStyle == FadeRight)
p2.setX(tmpImage.width());
else if (fadeStyle == FadeLeft)
p1.setX(tmpImage.width());

QLinearGradient gradient(p1, p2);
gradient.setColorAt(0, Qt::white);
gradient.setColorAt(0.25, QColor(0, 0, 0, 20));
gradient.setColorAt(1, Qt::transparent);

QPainter p(&tmpImage);
p.setCompositionMode(QPainter::CompositionMode_Des tinationIn);
p.fillRect(0, 0, tmpImage.width(), tmpImage.height(), gradient);
p.end();
}
return tmpImage;
}

sheeeng
25th January 2010, 10:07
Hi,

Thanks for all the advices.

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