C++ Qt未向平台插件呈现alpha通道
我有一个非常简单的应用程序,它渲染一个透明度为一半的透明小部件。一切都与默认环境平台(X11等)配合使用 这正如预期的那样有效 但是,如果使用我开发的自定义平台插件(基于最小示例),渲染图像没有alpha层 注意:事实证明,qt中的最小平台也可以做到这一点,但为了以防万一,我还将显示我的平台代码 这是站台屏幕C++ Qt未向平台插件呈现alpha通道,c++,qt,C++,Qt,我有一个非常简单的应用程序,它渲染一个透明度为一半的透明小部件。一切都与默认环境平台(X11等)配合使用 这正如预期的那样有效 但是,如果使用我开发的自定义平台插件(基于最小示例),渲染图像没有alpha层 注意:事实证明,qt中的最小平台也可以做到这一点,但为了以防万一,我还将显示我的平台代码 这是站台屏幕 QEncirisPlatformScreen::QEncirisPlatformScreen() : mDepth(32), mFormat(QImage::Forma
QEncirisPlatformScreen::QEncirisPlatformScreen()
: mDepth(32),
mFormat(QImage::Format_ARGB32_Premultiplied),
mGeometry(QRect(0, 0, 240, 320))
{
}
QEncirisPlatformScreen::~QEncirisPlatformScreen()
{
}
QRect QEncirisPlatformScreen::geometry() const
{
return mGeometry;
}
int QEncirisPlatformScreen::depth() const
{
return mDepth;
}
QImage::Format QEncirisPlatformScreen::format() const
{
return mFormat;
}
这是后备商店
QEncirisPlatformBackingStore::QEncirisPlatformBackingStore(QWindow *window)
: QPlatformBackingStore(window)
, mDebug(QEncirisPlatformIntegration::instance()->options() & QEncirisPlatformIntegration::DebugBackingStore)
{
if (mDebug)
qDebug() << "QMinimalBackingStore::QMinimalBackingStore:" << (quintptr)this;
mImage = new QImage(window->size(), QImage::Format_ARGB32_Premultiplied);
mImage->fill(Qt::transparent);
}
QEncirisPlatformBackingStore::~QEncirisPlatformBackingStore()
{
}
QPaintDevice *QEncirisPlatformBackingStore::paintDevice()
{
if (mDebug)
qDebug() << "QMinimalBackingStore::paintDevice";
return &(*mImage);
}
void QEncirisPlatformBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset)
{
Q_UNUSED(window);
Q_UNUSED(region);
Q_UNUSED(offset);
if (mDebug)
{
static int c = 0;
QString filename = QString("output%1.png").arg(c++, 4, 10, QLatin1Char('0'));
qDebug() << "QMinimalBackingStore::flush() saving contents to" << filename.toLocal8Bit().constData();
mImage->save(filename);
// this is false
qDebug() << "Has alpha " << mImage->data_ptr()->checkForAlphaPixels();
}
}
void QEncirisPlatformBackingStore::resize(const QSize &size, const QRegion &)
{
QImage::Format format = QGuiApplication::primaryScreen()->handle()->format();
if (mImage->size() != size)
mImage = new QImage(size, format);
}
QEncirisPlatformBackingStore::QEncirisPlatformBackingStore(QWindow*window)
:QPlatformBackingStore(窗口)
,mDebug(QEncirisPlatformIntegration::instance()->options()&QEncirisPlatformIntegration::DebugBackingStore)
{
如果(mDebug)
qDebug()填充(Qt::透明);
}
QEncirisPlatformBackingStore::~QEncirisPlatformBackingStore()
{
}
QPaintDevice*QEncirisPlatformBackingStore::paintDevice()
{
如果(mDebug)
qDebug()格式();
如果(图像->大小()!=大小)
mImage=新的QImage(大小、格式);
}
保存到文件系统的这些图像显示正确的小部件,但没有alpha透明度。背景颜色似乎是#efebe7(棕褐色),我没有在任何地方设置
如何使我的备份存储具有包含alpha/不透明度的mImage
QEncirisPlatformBackingStore::QEncirisPlatformBackingStore(QWindow *window)
: QPlatformBackingStore(window)
, mDebug(QEncirisPlatformIntegration::instance()->options() & QEncirisPlatformIntegration::DebugBackingStore)
{
if (mDebug)
qDebug() << "QMinimalBackingStore::QMinimalBackingStore:" << (quintptr)this;
mImage = new QImage(window->size(), QImage::Format_ARGB32_Premultiplied);
mImage->fill(Qt::transparent);
}
QEncirisPlatformBackingStore::~QEncirisPlatformBackingStore()
{
}
QPaintDevice *QEncirisPlatformBackingStore::paintDevice()
{
if (mDebug)
qDebug() << "QMinimalBackingStore::paintDevice";
return &(*mImage);
}
void QEncirisPlatformBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset)
{
Q_UNUSED(window);
Q_UNUSED(region);
Q_UNUSED(offset);
if (mDebug)
{
static int c = 0;
QString filename = QString("output%1.png").arg(c++, 4, 10, QLatin1Char('0'));
qDebug() << "QMinimalBackingStore::flush() saving contents to" << filename.toLocal8Bit().constData();
mImage->save(filename);
// this is false
qDebug() << "Has alpha " << mImage->data_ptr()->checkForAlphaPixels();
}
}
void QEncirisPlatformBackingStore::resize(const QSize &size, const QRegion &)
{
QImage::Format format = QGuiApplication::primaryScreen()->handle()->format();
if (mImage->size() != size)
mImage = new QImage(size, format);
}