void QDockWidgetPrivate::init() { Q_Q(QDockWidget); QDockWidgetLayout *layout = new QDockWidgetLayout(q); layout->setSizeConstraint(QLayout::SetMinAndMaxSize); QAbstractButton *button = new QDockWidgetTitleButton(q); button->setObjectName(QLatin1String("qt_dockwidget_floatbutton")); QObject::connect(button, SIGNAL(clicked()), q, SLOT(_q_toggleTopLevel())); layout->setWidgetForRole(QDockWidgetLayout::FloatButton, button); button = new QDockWidgetTitleButton(q); button->setObjectName(QLatin1String("qt_dockwidget_closebutton")); QObject::connect(button, SIGNAL(clicked()), q, SLOT(close())); layout->setWidgetForRole(QDockWidgetLayout::CloseButton, button); resizer = new QWidgetResizeHandler(q); resizer->setMovingEnabled(false); resizer->setActive(false); #ifndef QT_NO_ACTION toggleViewAction = new QAction(q); toggleViewAction->setCheckable(true); fixedWindowTitle = qt_setWindowTitle_helperHelper(q->windowTitle(), q); toggleViewAction->setText(fixedWindowTitle); QObject::connect(toggleViewAction, SIGNAL(triggered(bool)), q, SLOT(_q_toggleView(bool))); #endif updateButtons(); }
void QDockWidget::setTitleBarWidget(QWidget *widget) { Q_D(QDockWidget); QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout()); layout->setWidgetForRole(QDockWidgetLayout::TitleBar, widget); d->updateButtons(); if (isWindow()) { //this ensures the native decoration is drawn d->setWindowState(true /*floating*/, true /*unplug*/); } }
/*! Sets the widget for the dock widget to \a widget. If the dock widget is visible when \a widget is added, you must \l{QWidget::}{show()} it explicitly. Note that you must add the layout of the \a widget before you call this function; if not, the \a widget will not be visible. \sa widget() */ void QDockWidget::setWidget(QWidget *widget) { QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout()); layout->setWidgetForRole(QDockWidgetLayout::Content, widget); }