Pergunta

I am new to Qt and I am trying to create a DockWidget that docks on the right of the window. I set a maximum and minimum width for the dock (as you will see in the code below). This works if the dock widget is added with Qt::LeftDockWidgetArea, but when it is added with Qt::RightDockWidgetArea, The dock is "padded" out to the center of the window, like this: The red area shows the dock widget boundary.

I am probably not sizing the dock in the correct way.. Here is the code for this window:

int main(int argv, char** args)
{
    QApplication app(argv, args);
    QMainWindow window;
    QDesktopWidget* desktop = QApplication::desktop();
    //Docks
    QDockWidget* propertyDock = new QDockWidget("",&window);
    QWidget* propertyDockContents = new QWidget;

    //This sets the window in the center of the screen.
    int wWidth = 800; int wHeight = 600;
    window.setGeometry(QRect( (desktop->width()-wWidth)/2 , (desktop->height()-wHeight)/2 ,wWidth,wHeight));

    propertyDock->setAllowedAreas(Qt::RightDockWidgetArea);
    propertyDockContents->setMaximumWidth(200);
    propertyDockContents->setMinimumWidth(20);

    propertyDock->setWidget(propertyDockContents);
    window.addDockWidget(Qt::RightDockWidgetArea,propertyDock);

    window.show();

    return app.exec();
}

Is there a "correct" way to do this?

Foi útil?

Solução

As stated in the documentation:

Note: Creating a main window without a central widget is not supported. You must have a central widget even if it is just a placeholder.

Outras dicas

Yes! You can't creating a main window without a central widget, But you can set central widget's height to zero. MainWindow.cpp

centralWidget()->setMaximumHeight(0);   
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top