0

I design a GUI using Qt (5.12.4) on Widows 10, QtCreator and QtDesigner. In this one I add a lot of layers to do something which resize according to the size of the window.

But I was asking to add an image on top of this GUI on the middle. This can't be done without redoing all my layers, so is it possible to add an element (here an image) somewhere on the GUI without include it on one of my layers?

Thank you in advance for your help. Best regards

Mathieu Gauquelin
  • 601
  • 11
  • 35

1 Answers1

0

I finally follow the link of @Farshid616, and create my own class :

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);
    }
};

And add one item like this form my main function:

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);
}

And it is working !

Mathieu Gauquelin
  • 601
  • 11
  • 35