Important: Please read the Qt Code of Conduct -

Want to create a DockeWidget on the fly

  • I have a class like
    class MyQActions : public QObject {

    QAction* d_action;
    QMainWindow* d_parent;
    MyView* d_myView;



    MyQAction::MYQAction {

    d_actiont = act = new IN_CURRENT_POOL QAction(tr("Meny), this);
    connect(act, SIGNAL(triggered()), this, SLOT(myFunc()));



    I want to create a docke widget here on the fly
    // create a QWidget
    d_myView= new GQMyView(d_parent);

    if (corner == Qt::NoDockWidgetArea) {
    return NULL;
    } else {
    QDockWidget* w = addDockWidget(d_myView, tr(Label1"), true, (Qt::DockWidgetArea corner));


    class MyView: public QWidget {


    Can I do this and and When the user closes this QWidget I want to destroy this docked widget How to do it

  • Basically it should act a dialogue but I should be able to dock it

  • Lifetime Qt Champion


    If you put a widget in a QDockWidget then what you are going to close is the dock widget itself not the contained widget. So if you want to destroy both you'll have to put something like a "destroy me" button. Note that this is the kind of behavior that's a bit counter intuitive. Why do you want such a "dialog" for ?

  • The requirement is When I click the menu in QT Gui a window should come up as floating The window will be reporting a data . The user will see these reports and make changes in one of the other view of GUI
    Thus the requirement is if the user wants to dock it and keep it to side of other window and work side by side then he should be able and Once the user works done the user should be able to close /destroy the widget .Next time when The user clicks menu and again the new floating window should come up.

    This is because . if create the widget as docked it will remain it GUI . which is not required . This window should be created on the fly

  • Lifetime Qt Champion

    You can create it and not show it until needed.

  • Could you please guide me a little bit of how to do that and let me know some sample example

  • Lifetime Qt Champion

    Basically don't construct it until needed and that's pretty much it. You can also use the toggleViewAction if you want your user to be able to hide/show the dock widget at will.

Log in to reply