qmainwindow.cpp

来自「QT 开发环境里面一个很重要的文件」· C++ 代码 · 共 1,111 行 · 第 1/3 页

CPP
1,111
字号
    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); }/*!    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);    if (!toolbar->isAreaAllowed(area))        qWarning("QMainWIndow::addToolBar(): specified 'area' is not an allowed for this toolbar");    disconnect(this, SIGNAL(iconSizeChanged(QSize)),               toolbar, SLOT(_q_updateIconSize(QSize)));    disconnect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),               toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));    d->layout->removeWidget(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);    if (isVisible())        d->layout->relayout();}/*! \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;}/* Removes the toolbar from the mainwindow so that it can be added again. Does not   explicitly hide the toolbar. */static void qt_remove_toolbar_from_layout(QToolBar *toolbar, QMainWindowPrivate *d){    if (toolbar) {        QObject::disconnect(d->q_ptr, SIGNAL(iconSizeChanged(QSize)),                   toolbar, SLOT(_q_updateIconSize(QSize)));        QObject::disconnect(d->q_ptr, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),                   toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));        d->layout->removeWidget(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);    Q_ASSERT_X(toolbar->isAreaAllowed(toolBarArea(before)),               "QMainWIndow::insertToolBar", "specified 'area' is not an allowed area");    qt_remove_toolbar_from_layout(toolbar, d);    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);    if (isVisible())        d->layout->relayout();}/*!    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) {        qt_remove_toolbar_from_layout(toolbar, d_func());        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); }#endif // QT_NO_TOOLBAR#ifndef QT_NO_DOCKWIDGET/*! \property QMainWindow::animated    \brief whether manipulating dock widgets is animated    \since 4.2    When a dock widget is dragged over the main window, other dock widgets in the    window will adjust themselves to make space for the dragged widget. If this    property is set to true, their movement will be animated. The default value    is true.*/bool QMainWindow::isAnimated() const{    return d_func()->layout->animationEnabled;}void QMainWindow::setAnimated(bool enabled){    d_func()->layout->animationEnabled = enabled;}/*! \property QMainWindow::dockNestingEnabled    \brief whether docks can be nested    \since 4.2    If this property is set to false, dock areas can only contain a single row    (horizontal or vertical) of dock widgets. If this property is set to 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.*/bool QMainWindow::isDockNestingEnabled() const{    return d_func()->layout->dockNestingEnabled;}void QMainWindow::setDockNestingEnabled(bool enabled){    d_func()->layout->dockNestingEnabled = enabled;}static 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;    if (!dockwidget->isAreaAllowed(area))        qWarning("QMainWindow::addDockWidget(): specified 'area' is not an allowed for this widget");    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"))        return;    if (!dockwidget->isAreaAllowed(area))        qWarning("QMainWindow::addDockWidget(): specified 'area' is not an allowed for this widget");    // add a window to an area, placing done relative to the previous    d_func()->layout->addDockWidget(area, dockwidget, orientation);    if (isVisible())        d_func()->layout->relayout();}/*!    \fn void QMainWindow::splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation)    Splits the space covered by the \a first dock widget into two parts,    moves the \a first dock widget into the first part, and moves the    \a second dock widget into the second part.    The \a orientation specifies how the space is divided: A Qt::Horizontal    split places the second dock widget to the right of the first; a    Qt::Vertical split places the second dock widget below the first.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?