Qt:为什么我的图像背景在 LinuxFb 上是绿色的?
Qt: Why is the background of my image green on LinuxFb?
我的 Qt 应用程序应该在 HDMI 监视器上显示 JPEG 图像。当我 运行 我的 Linux 桌面环境中的应用程序时,图像显示正确。
但是,当我运行这个应用程序在LinuxFB下的嵌入式Linux环境中时,图像周围有大量绿色。
我的 1080p 显示器上的 NTSC (720x480) 彩条。
我的应用程序是用 QLabel 而不是 QWidget 编写的,并且没有任何活动 window。我尝试了多种解决方案,主要是使用 QPainter,但到目前为止,对背景外观没有任何影响。
int main (int argc, char *argv[])
{
QApplication app(argc, argv);
// Set the app palette to be transparent
app.setPalette(QPalette(Qt::transparent));
QPixmap input ("test.jpg");
QImage image(input.size(), QImage::Format_ARGB32_Premultiplied);
// Try to fill the QImage to be transparent
image.fill(Qt::transparent);
QPainter p(&image);
// Try a few things to get the painter background to be transparent
p.setOpacity(0.5); // 0 is invisible, 1 is opaque
p.setBackgroundMode(Qt::TransparentMode);
p.setBackground(Qt::transparent);
p.setBrush(Qt::transparent);
p.drawPixmap(0,0,input);
p.end();
QPixmap output = QPixmap::fromImage(image);
QLabel label (0, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
// Set the style sheet background color as transparent as well
label.setStyleSheet("background-color: transparent;");
//label.setStyleSheet("background-color: rgba(255,255,255,0);");
label.setPixmap(output);
label.setScaledContents(true);
label.show();
return app.exec();
}
应用程序执行如下
./my-Qt-application -qws -nomouse -display LinuxFb:/dev/fb1
我认为这与 Linux 帧缓冲区本身没有任何关系,因为绿色背景仅在我 运行 运行 Qt 应用程序时出现。
假设绿色背景来自 Qt,我该怎么做才能将其关闭(或使其透明)?
您没有采取任何措施来正确缩放标签。绿色背景是您的标签所在的位置 - 它可能是帧缓冲区的默认内容。填满整个屏幕,你就不会有那个问题了。
Qt 4.8(可能是4.x)
绿色背景来自QWSServer. You can change it by using QWSServer::setBackground()。
Qt 5.x
绿色背景的起源仍然是Qt,但是QWSServer
已经不存在了。我建议使用全屏 QWidget
作为背景。您可以使用包含 background-color: black;
.
的简单样式表更改 QWidget
的背景颜色
我的 Qt 应用程序应该在 HDMI 监视器上显示 JPEG 图像。当我 运行 我的 Linux 桌面环境中的应用程序时,图像显示正确。
但是,当我运行这个应用程序在LinuxFB下的嵌入式Linux环境中时,图像周围有大量绿色。
我的 1080p 显示器上的 NTSC (720x480) 彩条。
我的应用程序是用 QLabel 而不是 QWidget 编写的,并且没有任何活动 window。我尝试了多种解决方案,主要是使用 QPainter,但到目前为止,对背景外观没有任何影响。
int main (int argc, char *argv[])
{
QApplication app(argc, argv);
// Set the app palette to be transparent
app.setPalette(QPalette(Qt::transparent));
QPixmap input ("test.jpg");
QImage image(input.size(), QImage::Format_ARGB32_Premultiplied);
// Try to fill the QImage to be transparent
image.fill(Qt::transparent);
QPainter p(&image);
// Try a few things to get the painter background to be transparent
p.setOpacity(0.5); // 0 is invisible, 1 is opaque
p.setBackgroundMode(Qt::TransparentMode);
p.setBackground(Qt::transparent);
p.setBrush(Qt::transparent);
p.drawPixmap(0,0,input);
p.end();
QPixmap output = QPixmap::fromImage(image);
QLabel label (0, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
// Set the style sheet background color as transparent as well
label.setStyleSheet("background-color: transparent;");
//label.setStyleSheet("background-color: rgba(255,255,255,0);");
label.setPixmap(output);
label.setScaledContents(true);
label.show();
return app.exec();
}
应用程序执行如下
./my-Qt-application -qws -nomouse -display LinuxFb:/dev/fb1
我认为这与 Linux 帧缓冲区本身没有任何关系,因为绿色背景仅在我 运行 运行 Qt 应用程序时出现。
假设绿色背景来自 Qt,我该怎么做才能将其关闭(或使其透明)?
您没有采取任何措施来正确缩放标签。绿色背景是您的标签所在的位置 - 它可能是帧缓冲区的默认内容。填满整个屏幕,你就不会有那个问题了。
Qt 4.8(可能是4.x)
绿色背景来自QWSServer. You can change it by using QWSServer::setBackground()。
Qt 5.x
绿色背景的起源仍然是Qt,但是QWSServer
已经不存在了。我建议使用全屏 QWidget
作为背景。您可以使用包含 background-color: black;
.
QWidget
的背景颜色