qt - 在图层上方添加元素
问题描述
我在 Widows 10、QtCreator 和 QtDesigner 上使用 Qt (5.12.4) 设计了一个 GUI。在这个中,我添加了很多层来做一些根据窗口大小调整大小的事情。
但我要求在中间的这个 GUI 之上添加一个图像。如果不重做我的所有图层,这将无法完成,那么是否可以在 GUI 的某处添加一个元素(此处为图像)而不将其包含在我的一个图层中?
预先感谢您的帮助。最好的祝福
解决方案
我终于按照@Farshid616 的链接,创建了我自己的类:
class Overlay : public QWidget {
public:
explicit Overlay(QWidget *parent = nullptr) : QWidget(parent) {
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TransparentForMouseEvents);
QPixmap pic("://Ressources/img/tonneauGravesMarques.jpg");
int width = 117;
int height = 74;
QPixmap scaled=pic.scaled ( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
QLabel *label = new QLabel(this);
label->setPixmap(scaled);
this->resize(width, height);
}
};
并在我的主要功能中添加一个像这样的项目:
MainWindow::MainWindow(QWidget *parent) : AbstractMainWindow(parent)
{
qDebug() << "TarMainWindow::TarMainWindow";
ui->setupUi(this);
// Create widget for displaying image above all layers
m_overlay = new Overlay;
// Add this widget to main window
this->layout()->addWidget(m_overlay);
}
它正在工作!
推荐阅读
- c++ - DirectX::XMVECTOR 函数 XMVectorSetByIndex() 未设置浮点数 (C++)
- javascript - 如何在气泡图中按状态和在行/列中定位气泡
- php - 如何在对象中一次循环遍历 2 个或多个数组
- android - android中Google Docs预览中的RTL问题
- java - JTextPane 中的字体颜色同质性问题
- tensorflow - TensorFlow.js 无法在 Windows 10 中安装
- javascript - 为什么我无法从共享邮箱发送消息,即使删除了插件
- visual-studio-2015 - Visual Studio 2015 设计器不想显示表单 - 错误
- classification - 如何将数值类转换为 WEKA 中的因子?
- kubernetes - pod 网络错误