Cupidvogel
1st January 2016, 02:52
I am making a desktop carousel app. There I need to show image widgets, which might contain other sub-widgets as well. For that I am using a QFrame with the required image as background. Here is the image I am trying to use: image (http://imgur.com/RnSghvV). What I want is that only the image shows up, no background image or anything shows up as well, so to the user it looks like just the image. Qt provides a flag called Qt::WA_TranslucentBackground to do that. With it, this code works fine:
#ifndef main_h
#define main_h
#include <QFrame>
#include <QPixmap>
class MyFrame : public QFrame
{
public:
MyFrame(QWidget * parent);
virtual void paintEvent(QPaintEvent * e);
private:
QPixmap _pixmap;
};
#endif
#include <QApplication>
#include <QPainter>
#include "main.h"
MyFrame :: MyFrame(QWidget * parent) : QFrame(parent, Qt::Window|Qt::FramelessWindowHint)
{
setAttribute(Qt::WA_TranslucentBackground);
_pixmap.load("/Users/jaf/iPad_Vector.png");
resize(_pixmap.size());
}
void MyFrame :: paintEvent(QPaintEvent * /*e*/)
{
QPainter p(this);
p.drawPixmap(0,0,width(),height(), _pixmap);
}
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
MyFrame f(NULL);
f.show();
return app.exec();
}
However, the problem is that the iPad frame needs to show other elements within it (in the viewport area), and those elements are drawn and rendered through OpenGL, and OpenGL rendered elements show up as completely blank when placed in an element with the property Qt::WA_TranslucentBackground (I don't know whether it is a Qt or OpenGL bug or expected behavior) . As a result, the viewport shows up just like it is in the original iPad image, because the new widget that is supposed to sit there on top of it shows blank.
This happens only in Windows. Works fine in Mac. Is there any way to fix this? (Calling native C++ APIs on Windows is acceptable. C# as well, provided they can be called through Qt, like we can call native Cocoa code on Mac from Qt)
Or can the iPad image be used as background in any other way?
#ifndef main_h
#define main_h
#include <QFrame>
#include <QPixmap>
class MyFrame : public QFrame
{
public:
MyFrame(QWidget * parent);
virtual void paintEvent(QPaintEvent * e);
private:
QPixmap _pixmap;
};
#endif
#include <QApplication>
#include <QPainter>
#include "main.h"
MyFrame :: MyFrame(QWidget * parent) : QFrame(parent, Qt::Window|Qt::FramelessWindowHint)
{
setAttribute(Qt::WA_TranslucentBackground);
_pixmap.load("/Users/jaf/iPad_Vector.png");
resize(_pixmap.size());
}
void MyFrame :: paintEvent(QPaintEvent * /*e*/)
{
QPainter p(this);
p.drawPixmap(0,0,width(),height(), _pixmap);
}
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
MyFrame f(NULL);
f.show();
return app.exec();
}
However, the problem is that the iPad frame needs to show other elements within it (in the viewport area), and those elements are drawn and rendered through OpenGL, and OpenGL rendered elements show up as completely blank when placed in an element with the property Qt::WA_TranslucentBackground (I don't know whether it is a Qt or OpenGL bug or expected behavior) . As a result, the viewport shows up just like it is in the original iPad image, because the new widget that is supposed to sit there on top of it shows blank.
This happens only in Windows. Works fine in Mac. Is there any way to fix this? (Calling native C++ APIs on Windows is acceptable. C# as well, provided they can be called through Qt, like we can call native Cocoa code on Mac from Qt)
Or can the iPad image be used as background in any other way?