📄 qwidget.cpp
字号:
\sa Qt::WindowState setWindowState() */Qt::WindowStates QWidget::windowState() const{ return (Qt::WindowStates)data->window_state;}/*!\internal The function sets the window state on child widgets similar to setWindowState(). The difference is that the window state changed event has the isOverride() flag set. It exists mainly to keep Q3Workspace working. */void QWidget::overrideWindowState(Qt::WindowStates newstate){ QWindowStateChangeEvent e((Qt::WindowStates)data->window_state, true); data->window_state = newstate; QApplication::sendEvent(this, &e);}/*! \fn void QWidget::setWindowState(Qt::WindowStates windowState) Sets the window state to \a windowState. The window state is a OR'ed combination of Qt::WindowState: Qt::WindowMinimized, Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive. If the window is not visible (i.e. isVisible() returns false), the window state will take effect when show() is called. For visible windows, the change is immediate. For example, to toggle between full-screen and mormal mode, use the following code: \code w->setWindowState(w->windowState() ^ Qt::WindowFullScreen); \endcode In order to restore and activate a minimized window (while preserving its maximized and/or full-screen state), use the following: \code w->setWindowState(w->windowState() & ~Qt::WindowMinimized | Qt::WindowActive); \endcode Note: On some window systems Qt::WindowActive is not immediate, and may be ignored in certain cases. When the window state changes, the widget receives a changeEvent() of type QEvent::WindowStateChange. \sa Qt::WindowState windowState()*//*! \property QWidget::fullScreen \brief whether the widget is full screen \sa windowState(), minimized, maximized*/bool QWidget::isFullScreen() const{ return data->window_state & Qt::WindowFullScreen; }/*! Shows the widget in full-screen mode. Calling this function only affects \l{isWindow()}{windows}. To return from full-screen mode, call showNormal(). Full-screen mode works fine under Windows, but has certain problems under X. These problems are due to limitations of the ICCCM protocol that specifies the communication between X11 clients and the window manager. ICCCM simply does not understand the concept of non-decorated full-screen windows. Therefore, the best we can do is to request a borderless window and place and resize it to fill the entire screen. Depending on the window manager, this may or may not work. The borderless window is requested using MOTIF hints, which are at least partially supported by virtually all modern window managers. An alternative would be to bypass the window manager entirely and create a window with the Qt::WX11BypassWM flag. This has other severe problems though, like totally broken keyboard focus and very strange effects on desktop changes or when the user raises other windows. X11 window managers that follow modern post-ICCCM specifications support full-screen mode properly. \sa showNormal(), showMaximized(), show(), hide(), isVisible()*/void QWidget::showFullScreen(){ ensurePolished();#ifdef QT3_SUPPORT if (parent()) QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);#endif setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized)) | Qt::WindowFullScreen); show(); activateWindow();}/*! Shows the widget maximized. Calling this function only affects \l{isWindow()}{windows}. On X11, this function may not work properly with certain window managers. See \l{geometry.html}{Window Geometry} for an explanation. \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()*/void QWidget::showMaximized(){ ensurePolished();#ifdef QT3_SUPPORT if (parent()) QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);#endif setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) | Qt::WindowMaximized); show();}/*! Restores the widget after it has been maximized or minimized. Calling this function only affects \l{isWindow()}{windows}. \sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible()*/void QWidget::showNormal(){ ensurePolished();#ifdef QT3_SUPPORT if (parent()) QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);#endif setWindowState(windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)); show();}/*! Returns true if this widget would become enabled if \a ancestor is enabled; otherwise returns false. This is the case if neither the widget itself nor every parent up to but excluding \a ancestor has been explicitly disabled. isEnabledTo(0) is equivalent to isEnabled(). \sa setEnabled() enabled*/bool QWidget::isEnabledTo(QWidget* ancestor) const{ const QWidget * w = this; while (w && !w->testAttribute(Qt::WA_ForceDisabled) && !w->isWindow() && w->parentWidget() && w->parentWidget() != ancestor) w = w->parentWidget(); return !w->testAttribute(Qt::WA_ForceDisabled);}#ifndef QT_NO_ACTION/*! Appends the action \a action to this widget's list of actions. All QWidgets have a list of \l{QAction}s, however they can be represented graphically in many different ways. The default use of the QAction list (as returned by actions()) is to create a context QMenu. A QWidget should only have one of each action. \sa removeAction() QMenu*/void QWidget::addAction(QAction *action){ insertAction(0, action);}/*! Appends the actions \a actions to this widget's list of actions. \sa removeAction() QMenu addAction()*/void QWidget::addActions(QList<QAction*> actions){ for(int i = 0; i < actions.count(); i++) insertAction(0, actions.at(i));}/*! Inserts the action \a action to this widget's list of actions, before the action \a before. It appends the action if \a before is 0 or \a before is not a valid action for this widget. A QWidget should only have one of each action. \sa addAction()*/void QWidget::insertAction(QAction *before, QAction *action){ if(!action) { qWarning("Attempt to insert null action!"); return; } Q_D(QWidget); if(d->actions.contains(action)) removeAction(action); int pos = d->actions.indexOf(before); if (pos < 0) { before = 0; pos = d->actions.size(); } d->actions.insert(pos, action); QActionPrivate *apriv = action->d_func(); apriv->widgets.append(this); QActionEvent e(QEvent::ActionAdded, action, before); QApplication::sendEvent(this, &e);}/*! Inserts the actions \a actions to this widget's list of actions, before the action \a before. It appends the action if \a before is 0 or \a before is not a valid action for this widget. A QWidget should only have one of each action. \sa removeAction() QMenu insertAction()*/void QWidget::insertActions(QAction *before, QList<QAction*> actions){ for(int i = 0; i < actions.count(); ++i) insertAction(before, actions.at(i));}/*! Removes the action \a action from this widget's list of actions.*/void QWidget::removeAction(QAction *action){ if (!action) return; Q_D(QWidget); QActionPrivate *apriv = action->d_func(); apriv->widgets.removeAll(this); if (d->actions.removeAll(action)) { QActionEvent e(QEvent::ActionRemoved, action); QApplication::sendEvent(this, &e); }}/*! Returns the (possibly empty) list of this widget's actions.*/QList<QAction*> QWidget::actions() const{ Q_D(const QWidget); return d->actions;}#endif // QT_NO_ACTION/*! \fn bool QWidget::isEnabledToTLW() const \obsolete This function is deprecated. It is equivalent to isEnabled()*//*! \property QWidget::enabled \brief whether the widget is enabled An enabled widget handles keyboard and mouse events; a disabled widget does not. Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled, you can use the changeEvent() with type QEvent::EnabledChange. Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled. \sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent()*/void QWidget::setEnabled(bool enable){ Q_D(QWidget); setAttribute(Qt::WA_ForceDisabled, !enable); d->setEnabled_helper(enable);}void QWidgetPrivate::setEnabled_helper(bool enable){ Q_Q(QWidget); if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled()) return; // nothing we can do if (enable != q->testAttribute(Qt::WA_Disabled)) return; // nothing to do q->setAttribute(Qt::WA_Disabled, !enable); updateSystemBackground(); if (!enable && q->window()->focusWidget() == q) { bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled()); if (!parentIsEnabled || !q->focusNextChild()) q->clearFocus(); } Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceDisabled : Qt::WA_Disabled; for (int i = 0; i < children.size(); ++i) { QWidget *w = qobject_cast<QWidget *>(children.at(i)); if (w && !w->testAttribute(attribute)) w->d_func()->setEnabled_helper(enable); }#if defined(Q_WS_X11) if (q->testAttribute(Qt::WA_SetCursor)) { // enforce the windows behavior of clearing the cursor on // disabled widgets extern void qt_x11_enforce_cursor(QWidget * w); // defined in qwidget_x11.cpp qt_x11_enforce_cursor(q); }#endif#ifdef Q_WS_WIN QWinInputContext::enable(q, q->testAttribute(Qt::WA_InputMethodEnabled) && enable);#endif QEvent e(QEvent::EnabledChange); QApplication::sendEvent(q, &e);#ifdef QT3_SUPPORT q->enabledChange(!enable); // compatibility#endif}/*! \property QWidget::acceptDrops \brief whether drop events are enabled for this widget Setting this property to true announces to the system that this widget \e may be able to accept drop events. If the widget is the desktop (QWidget::(windowType() == Qt::Desktop)), this may fail if another application is using the desktop; you can call acceptDrops() to test if this occurs. \warning Do not modify this property in a Drag&Drop event handler.*/bool QWidget::acceptDrops() const{ return testAttribute(Qt::WA_AcceptDrops);}void QWidget::setAcceptDrops(bool on){ setAttribute(Qt::WA_AcceptDrops, on);}/*! \fn void QWidget::enabledChange(bool) \internal \obsolete*//*! \fn void QWidget::paletteChange(const QPalette &) \internal \obsolete*//*! \fn void QWidget::fontChange(const QFont &) \internal \obsolete*//*! \fn void QWidget::windowActivationChange(bool) \internal \obsolete*//*! \fn void QWidget::languageChange() \obsolete*//*! \fn void QWidget::styleChange(QStyle& style) \internal \obsolete*//*! Disables widget input events if \a disable is true; otherwise enables input events. See the \l enabled documentation for more information. \sa isEnabledTo(), QKeyEvent, QMous
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -