I managed to find a working solution -
main.h:
#ifndef main_h
#define main_h
#include <QFrame>
#include <QPixmap>
{
public:
private:
};
#endif
#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
To copy to clipboard, switch view to plain text mode
main.cpp
#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());
}
{
p.drawPixmap(0,0,width(),height(), _pixmap);
}
int main(int argc, char ** argv)
{
MyFrame f(NULL);
f.show();
return app.exec();
}
#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();
}
To copy to clipboard, switch view to plain text mode
This works. However, in my use case, I need to display an image that is rendered via GL inside the QFrame (specifically, in the viewport within the iPad image we can see here). In Windows, setting the Qt::WA_TranslucentBackground property makes that GL-rendered image invisible. It works fine in Mac, though. How can I make it behave in the same way without using Qt::WA_TranslucentBackground?
Bookmarks