2013-03-27 810 views
0

我有一个QTDesigner对话框,并带有一个QDockWidget作为主窗口小部件。当我停靠到主窗口并显示对话框时,自动自动隐藏,但允许我使用鼠标显示/隐藏它。我想默认情况下保持可见。 如果我使用鼠标将其大小调整为大约2/3的屏幕大小,然后关闭对话框并稍后显示,则即使我以最后一个大尺寸关闭应用程序,它也可以正常工作。QDockWidget启动时自动隐藏

Theese是我clases:

/** created automatically by QT compiler */ 
class Ui_OfsIndSelAttribBase 
{ 
    public: 
     QWidget *dockWidgetContents; 
     QVBoxLayout *verticalLayout_10; 
     QGroupBox *_p_gB_Filters; 
     QVBoxLayout *verticalLayout_9; 
     QVBoxLayout *verticalLayout_4; 
     .... 

     void setupUi(QDockWidget *dockWidget) 
     { 
      if (dockWidget->objectName().isEmpty()) 
       dockWidget->setObjectName(QString::fromUtf8("dockWidget")); 
      dockWidget->resize(352, 789); 
      dockWidget->setFloating(false); 
      dockWidgetContents = new QWidget(); 
      dockWidgetContents->setObjectName(QString::fromUtf8("dockWidgetContents")); 
      ... 
     } 
}; 

我的对话框分类:

class FCSDockableInputDataQt: public QDockWidget 
{ 
    Q_OBJECT 

    public: 
     /** GetMainWindow() returns a valid QT main window */ 
     FCSDockableInputDataQt(Qt::DockWidgetArea do = Qt::BottomDockWidgetArea, 
           Qt::WFlags f=0) : 
      QDockWidget("MyDialog", GetMainWindow(), f) 
     { 
      .... 
     } 
}; 

/** this is my dialog management class */ 
class OfsIndSelAttribQt : public FCSDockableInputDataQt, 
          public Ui::OfsIndSelAttribBase 
{ 
    Q_OBJECT 

    OfsIndSelAttribQt() : 
     FCSDockableInputDataQt(Qt::RightDockWidgetArea) 
    { 
     setupUi(this); 
     setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); 
     setFloating(false); 
     .... 
    } 
}; 

回答

1

你想使QDockWidget隐藏在窗口创建时,但随后切换显示或当你点击一个隐藏某处按钮,还是其他类似的东西?在你的setupUi方法中调用QDockWidget :: hide(),然后在切换QDockWidget的时候添加一个小切换按钮,告诉QDockWidget是否显示或隐藏。

0

连接QAppltion信号aboutToQuit()到您的dockwidget的SLOT说onQuit:

QObject::connect(QApplication(), SIGNAL(aboutToQuit()), this, SLOT(onQuit())); 

SLOT应该是这样的:

void CustomDock::onQuit() 
{ 
    setVisible(false); 
} 

所以。当关闭你的应用程序时,码头是隐藏的。如果您再次启动您的应用程序,QT会将CustomDock状态恢复为隐藏状态。