2012-04-09 95 views
3

我是Qt新手,我試圖創建一個停靠在窗口右側的DockWidget。我爲碼頭設置了最大和最小寬度(如下面的代碼所示)。這適用於碼頭窗口小部件添加Qt::LeftDockWidgetArea,但是當它被添加Qt::RightDockWidgetArea,該碼頭是「填充」出到窗口的中心,就像這樣: The red area shows the dock widget boundary. QDockWidget大小錯誤,當停靠在主窗口的右側

我可能不施膠在被告席正確的方法..這裏是這個窗口的代碼:

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

有沒有一個「正確」的方式來做到這一點?

回答

3

如文檔中表示:

注:沒有一箇中央物件創建一個主窗口,不支持。即使只是一個佔位符,您也必須擁有一箇中央控件。