0
votes

I have a QT main window and on top of this I want to add a widget ( containing buttons), as similar to image below. If I add a dock widget , it is added in separate row, but not added as overlay on existing main window. enter image description here Any inputs ?

2
My other answer contains a full example of having a transparent overlay over another window. You could tailor the overlay to draw what you want - probably you could reuse a set of pushbuttons with custom styling.Kuba hasn't forgotten Monica

2 Answers

0
votes

The easiest is to set your overlay widget's parent to be the main window. But because it will not be in any layout you have to take care of its geometry yourself. In case you want to have multiple overlays, the last added will be the top most.

#include <QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QMainWindow *window = new QMainWindow();
    QWidget *centralWiddget = new QWidget();
    window->setCentralWidget(centralWiddget);

    QVBoxLayout *layout = new QVBoxLayout(centralWiddget);

    QPushButton *button = new QPushButton("Button in a layout");
    layout->addWidget(button);

    QPushButton *overlayButton = new QPushButton("Button overlay");
    overlayButton->setParent(window);
    overlayButton->setGeometry(40, 40, 120, 30)

    window->show();

    return app.exec();
}
0
votes

You should look into using QStackedLayout to so this.