📄 qmainwindow.cpp
字号:
/*! \since 4.2 Returns the menu bar for the main window. This function returns null if a menu bar hasn't been constructed yet.*/QWidget *QMainWindow::menuWidget() const{ QWidget *menuBar = d_func()->layout->menuBar(); return menuBar;}/*! \since 4.2 Sets the menu bar for the main window to \a menuBar. QMainWindow takes ownership of the \a menuBar pointer and deletes it at the appropriate time.*/void QMainWindow::setMenuWidget(QWidget *menuBar){ Q_D(QMainWindow); if (d->layout->menuBar() && d->layout->menuBar() != menuBar) delete d->layout->menuBar(); d->layout->setMenuBar(menuBar);}#endif // QT_NO_MENUBAR#ifndef QT_NO_STATUSBAR/*! Returns the status bar for the main window. This function creates and returns an empty status bar if the status bar does not exist. \sa setStatusBar()*/QStatusBar *QMainWindow::statusBar() const{ QStatusBar *statusbar = d_func()->layout->statusBar(); if (!statusbar) { QMainWindow *self = const_cast<QMainWindow *>(this); statusbar = new QStatusBar(self); statusbar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); self->setStatusBar(statusbar); } return statusbar;}/*! Sets the status bar for the main window to \a statusbar. Setting the status bar to 0 will remove it from the main window. Note that QMainWindow takes ownership of the \a statusbar pointer and deletes it at the appropriate time. \sa statusBar()*/void QMainWindow::setStatusBar(QStatusBar *statusbar){ Q_D(QMainWindow); if (d->layout->statusBar() && d->layout->statusBar() != statusbar) delete d->layout->statusBar(); d->layout->setStatusBar(statusbar);}#endif // QT_NO_STATUSBAR/*! Returns the central widget for the main window. This function returns zero if the central widget has not been set. \sa setCentralWidget()*/QWidget *QMainWindow::centralWidget() const{ return d_func()->layout->centralWidget(); }/*! Sets the given \a widget to be the main window's central widget. Note: QMainWindow takes ownership of the \a widget pointer and deletes it at the appropriate time. \sa centralWidget()*/void QMainWindow::setCentralWidget(QWidget *widget){ Q_D(QMainWindow); if (d->layout->centralWidget() && d->layout->centralWidget() != widget) delete d->layout->centralWidget(); d->layout->setCentralWidget(widget);}#ifndef QT_NO_DOCKWIDGET/*! Sets the given dock widget \a area to occupy the specified \a corner. \sa corner()*/void QMainWindow::setCorner(Qt::Corner corner, Qt::DockWidgetArea area){ bool valid = false; switch (corner) { case Qt::TopLeftCorner: valid = (area == Qt::TopDockWidgetArea || area == Qt::LeftDockWidgetArea); break; case Qt::TopRightCorner: valid = (area == Qt::TopDockWidgetArea || area == Qt::RightDockWidgetArea); break; case Qt::BottomLeftCorner: valid = (area == Qt::BottomDockWidgetArea || area == Qt::LeftDockWidgetArea); break; case Qt::BottomRightCorner: valid = (area == Qt::BottomDockWidgetArea || area == Qt::RightDockWidgetArea); break; } if (!valid) qWarning("QMainWindow::setCorner(): 'area' is not valid for 'corner'"); else d_func()->layout->setCorner(corner, area);}/*! Returns the dock widget area that occupies the specified \a corner. \sa setCorner()*/Qt::DockWidgetArea QMainWindow::corner(Qt::Corner corner) const{ return d_func()->layout->corner(corner); }#endif#ifndef QT_NO_TOOLBARstatic bool checkToolBarArea(Qt::ToolBarArea area, const char *where){ switch (area) { case Qt::LeftToolBarArea: case Qt::RightToolBarArea: case Qt::TopToolBarArea: case Qt::BottomToolBarArea: return true; default: break; } qWarning("%s: invalid 'area' argument", where); return false;}/*! Adds a toolbar break to the given \a area after all the other objects that are present.*/void QMainWindow::addToolBarBreak(Qt::ToolBarArea area){ if (!checkToolBarArea(area, "QMainWindow::addToolBarBreak")) return; d_func()->layout->addToolBarBreak(area);}/*! Inserts a toolbar break before the toolbar specified by \a before.*/void QMainWindow::insertToolBarBreak(QToolBar *before){ d_func()->layout->insertToolBarBreak(before); }/*! Removes a toolbar break previously inserted before the toolbar specified by \a before.*/void QMainWindow::removeToolBarBreak(QToolBar *before){ Q_D(QMainWindow); d->layout->removeToolBarBreak(before);}/*! Adds the \a toolbar into the specified \a area in this main window. The \a toolbar is placed at the end of the current tool bar block (i.e. line). If the main window already manages \a toolbar then it will only move the toolbar to \a area. \sa insertToolBar() addToolBarBreak() insertToolBarBreak()*/void QMainWindow::addToolBar(Qt::ToolBarArea area, QToolBar *toolbar){ if (!checkToolBarArea(area, "QMainWindow::addToolBar")) return; Q_D(QMainWindow); disconnect(this, SIGNAL(iconSizeChanged(QSize)), toolbar, SLOT(_q_updateIconSize(QSize))); disconnect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle))); if (!d->layout->usesHIToolBar(toolbar)) { d->layout->removeWidget(toolbar); } else { d->layout->removeToolBar(toolbar); } toolbar->d_func()->_q_updateIconSize(d->iconSize); toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle); connect(this, SIGNAL(iconSizeChanged(QSize)), toolbar, SLOT(_q_updateIconSize(QSize))); connect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle))); d->layout->addToolBar(area, toolbar);}/*! \overload Equivalent of calling addToolBar(Qt::TopToolBarArea, \a toolbar)*/void QMainWindow::addToolBar(QToolBar *toolbar){ addToolBar(Qt::TopToolBarArea, toolbar); }/*! \overload Creates a QToolBar object, setting its window title to \a title, and inserts it into the top toolbar area. \sa setWindowTitle()*/QToolBar *QMainWindow::addToolBar(const QString &title){ QToolBar *toolBar = new QToolBar(this); toolBar->setWindowTitle(title); addToolBar(toolBar); return toolBar;}/*! Inserts the \a toolbar into the area occupied by the \a before toolbar so that it appears before it. For example, in normal left-to-right layout operation, this means that \a toolbar will appear to the left of the toolbar specified by \a before in a horizontal toolbar area. \sa insertToolBarBreak() addToolBar() addToolBarBreak()*/void QMainWindow::insertToolBar(QToolBar *before, QToolBar *toolbar){ Q_D(QMainWindow); d->layout->removeToolBar(toolbar); toolbar->d_func()->_q_updateIconSize(d->iconSize); toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle); connect(this, SIGNAL(iconSizeChanged(QSize)), toolbar, SLOT(_q_updateIconSize(QSize))); connect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle))); d->layout->insertToolBar(before, toolbar);}/*! Removes the \a toolbar from the main window layout and hides it. Note that the \a toolbar is \e not deleted.*/void QMainWindow::removeToolBar(QToolBar *toolbar){ if (toolbar) { d_func()->layout->removeToolBar(toolbar); toolbar->hide(); }}/*! Returns the Qt::ToolBarArea for \a toolbar. If \a toolbar has not been added to the main window, this function returns \c Qt::NoToolBarArea. \sa addToolBar() addToolBarBreak() Qt::ToolBarArea*/Qt::ToolBarArea QMainWindow::toolBarArea(QToolBar *toolbar) const{ return d_func()->layout->toolBarArea(toolbar); }/*! Returns whether there is a toolbar break before the \a toolbar. \sa addToolBarBreak(), insertToolBarBreak()*/bool QMainWindow::toolBarBreak(QToolBar *toolbar) const{ return d_func()->layout->toolBarBreak(toolbar);}#endif // QT_NO_TOOLBAR#ifndef QT_NO_DOCKWIDGET/*! \property QMainWindow::animated \brief whether manipulating dock widgets and tool bars is animated \since 4.2 When a dock widget or tool bar is dragged over the main window, the main window adjusts its contents to indicate where the dock widget or tool bar will be docked if it is dropped. Setting this property causes QMainWindow to move its contents in a smooth animation. Clearing this property causes the contents to snap into their new positions. By default, this property is set. It may be cleared if the main window contains widgets which are slow at resizing or repainting themselves. Setting this property is identical to setting the AnimatedDocks option using setDockOptions().*/bool QMainWindow::isAnimated() const{ Q_D(const QMainWindow); return d->layout->dockOptions & AnimatedDocks;}void QMainWindow::setAnimated(bool enabled){ Q_D(QMainWindow); DockOptions opts = d->layout->dockOptions; if (enabled) opts |= AnimatedDocks; else opts &= ~AnimatedDocks; d->layout->setDockOptions(opts);}/*! \property QMainWindow::dockNestingEnabled \brief whether docks can be nested \since 4.2 If this property is false, dock areas can only contain a single row (horizontal or vertical) of dock widgets. If this property is true, the area occupied by a dock widget can be split in either direction to contain more dock widgets. Dock nesting is only necessary in applications that contain a lot of dock widgets. It gives the user greater freedom in organizing their main window. However, dock nesting leads to more complex (and less intuitive) behavior when a dock widget is dragged over the main window, since there are more ways in which a dropped dock widget may be placed in the dock area. Setting this property is identical to setting the AllowNestedDocks option using setDockOptions().*/bool QMainWindow::isDockNestingEnabled() const{ Q_D(const QMainWindow); return d->layout->dockOptions & AllowNestedDocks;}void QMainWindow::setDockNestingEnabled(bool enabled){ Q_D(QMainWindow); DockOptions opts = d->layout->dockOptions; if (enabled) opts |= AllowNestedDocks; else opts &= ~AllowNestedDocks; d->layout->setDockOptions(opts);}#if 0/*! \property QMainWindow::verticalTabsEnabled \brief whether left and right dock areas use vertical tabs \since 4.2 If this property is set to false, dock areas containing tabbed dock widgets display horizontal tabs, simmilar to Visual Studio. If this property is set to true, then the right and left dock areas display vertical tabs, simmilar to KDevelop. This property should be set before any dock widgets are added to the main window.*/bool QMainWindow::verticalTabsEnabled() const{ return d_func()->layout->verticalTabsEnabled();}void QMainWindow::setVerticalTabsEnabled(bool enabled){ d_func()->layout->setVerticalTabsEnabled(enabled);}#endifstatic bool checkDockWidgetArea(Qt::DockWidgetArea area, const char *where){ switch (area) { case Qt::LeftDockWidgetArea: case Qt::RightDockWidgetArea: case Qt::TopDockWidgetArea: case Qt::BottomDockWidgetArea: return true; default: break; } qWarning("%s: invalid 'area' argument", where); return false;}/*! Adds the given \a dockwidget to the specified \a area.*/void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget){ if (!checkDockWidgetArea(area, "QMainWindow::addDockWidget")) return; Qt::Orientation orientation = Qt::Vertical; switch (area) { case Qt::TopDockWidgetArea: case Qt::BottomDockWidgetArea: orientation = Qt::Horizontal; break; default: break; } d_func()->layout->removeWidget(dockwidget); // in case it was already in here addDockWidget(area, dockwidget, orientation);#ifdef Q_WS_MAC //drawer support extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp if (qt_mac_is_macdrawer(dockwidget)) { extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp window()->createWinId(); dockwidget->window()->createWinId(); qt_mac_set_drawer_preferred_edge(dockwidget, area); if (dockwidget->isVisible()) { dockwidget->hide(); dockwidget->show(); } }#endif}/*! Adds \a dockwidget into the given \a area in the direction specified by the \a orientation.*/void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget, Qt::Orientation orientation){ if (!checkDockWidgetArea(area, "QMainWindow::addDockWidget"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -