Использование QWidget::setAttribute(Qt::WA_TranslucentBackground);
. Обратите внимание, что для этого также необходимо установить Qt::FramelessWindowHint
.
Этот пример работает для меня:
#include <QtGui>
class Dialog : public QDialog
{
public:
Dialog() : QDialog(0, Qt::FramelessWindowHint) // hint is required on Windows
{
QPushButton *button = new QPushButton("Some Button", this);
setAttribute(Qt::WA_TranslucentBackground);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog d;
d.show();
return a.exec();
}
Что касается скругленных углов, QWidget::setMask()
поможет.
EDIT: В ответ на другой вопрос ниже в комментариях, вот рабочий пример, который использует изображение в файле ресурсов, и приоритет QWidget::paintEvent()
:
#include <QtGui>
class Dialog : public QDialog
{
public:
Dialog() : QDialog(0, Qt::FramelessWindowHint) // hint is required on Windows
{
setFixedSize(500, 500); // size of the background image
QPushButton *button = new QPushButton("Some Button", this);
setAttribute(Qt::WA_TranslucentBackground);
}
protected:
void paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.drawImage(QRectF(0, 0, 500, 500), QImage(":/resources/image.png"));
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog d;
d.show();
return a.exec();
}
возможно дубликат [A кварт виджета с полностью прозрачный фон] (http://stackoverflow.com/questions/4278723/a-qt-widget-with-fully-transparent-background) –