![](/img/trans.png)
[英]QWidget render to QPixmap seems to ignore "border-radius" setting of stylesheet
[英]Render QWidget in QPixmap with system background
當我使用帶有透明對象的 QOpenGLWidget 子項渲染 QWidget 時,當我嘗試截取如下圖所示的屏幕截圖時,我觀察到了日光效應:
問題來自系統背景,因為當我刪除它時,問題消失了:
我的問題是:在具有系統背景的QPixmap 上渲染QWidget 的解決方案是什么?
這是我的渲染代碼:
QWidget widget;
QPixmap pixmap(widget.size());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
widget.render(&painter, QPoint(), QRegion(), QWidget::DrawWindowBackground /* the problem is this render flag */ | QWidget::IgnoreMask | QWidget::DrawChildren);
pixmap.save("screenshot.png");
屬性setAutoFillBackground(true);
和方法grab();
像第一個屏幕截圖一樣做。
編輯:沒有 OpenGL 問題。 當我混合兩個像素圖(第一個與背景,第二個與小部件子項)時,曝光問題仍然存在。
一種解決方案是在我的 QOpenGLWidget 中將角色為 Window 的 QPalette 設置為黑色。
QPalette currentWidgetPalette{ palette() };
currentWidgetPalette.setColor(QPalette::Window, Qt::black);
setPalette(currentWidgetPalette);
編輯:我找到了一個解決方案,可以使用我的小部件在 tansparent 和源中繪制目標,以正確組成像素圖。
painter.setCompositionMode(QPainter::CompositionMode_Destination);
painter.fillRect(result.rect(), Qt::transparent);
painter.setCompositionMode(QPainter::CompositionMode_Source);
widget.render(&painter, QPoint(), QRegion(), QWidget::DrawWindowBackground | QWidget::IgnoreMask | QWidget::DrawChildren);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.