Important: Please read the Qt Code of Conduct -

QWidget over and outside parent QMainwindow

  • I have a mainWindow and a widget that will be a child of that main window. Below is a code example created with QTCreator.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        //create test widget
            QWidget* blue_widget = new QWidget(); //no parent
            blue_widget->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool );
            //create test widget END
        delete ui;

    Right now I can only see the part of the blue_widget that is inside the boundaries of the main window. I would like to be able to have the totality of the blue_widget shown. How can I prevent the main window cutting the blue_widget like that ? I really need to have the blue_widget to be a child of the main window.

    Thanks for the help.

  • Lifetime Qt Champion


    Why not set it as central widget ? Or put it in a QDockWidget ?

  • Hi,
    You should set the blue_widget as the central widget of the MainWindow, or fill the MainWindow with a QWidget in designer and set your blueWidget to that one. In designer you should set MainWindow to be e.g. a GridLayout, or any other layout. Leaving the MAinWindow without a layout will not force you Blue Widget to resize according the MainWindow size.

  • Lifetime Qt Champion

    As long as the widget is a child of the mainwindow, it will be clipped to it.
    To have a floating window that is not clipped to parent, you can use QDialogs or
    simply do not set the parent. ( you must manually delete it then)

    Its by design that widgets are clipped. So you must make it a true window type ( as Dialog is) ( or using Qt::Window flag)
    or dont give it parent.

Log in to reply