📄 qwidget.cpp
字号:
#endif}/* Returns the widget's clipping rectangle.*/QRect QWidgetPrivate::clipRect() const{ Q_Q(const QWidget); const QWidget * w = q; if (!w->isVisible()) return QRect(); QRect r = q->rect(); int ox = 0; int oy = 0; while (w && w->isVisible() && !w->isWindow() && w->parentWidget()) { ox -= w->x(); oy -= w->y(); w = w->parentWidget(); r &= QRect(ox, oy, w->width(), w->height()); } return r;}/* Returns the widget's clipping region (without siblings).*/QRegion QWidgetPrivate::clipRegion() const{ Q_Q(const QWidget); if (!q->isVisible()) return QRegion(); QRegion r(q->rect()); const QWidget * w = q; const QWidget *ignoreUpTo; int ox = 0; int oy = 0; while (w && w->isVisible() && !w->isWindow() && w->parentWidget()) { ox -= w->x(); oy -= w->y(); ignoreUpTo = w; w = w->parentWidget(); r &= QRegion(ox, oy, w->width(), w->height()); int i = 0; while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo)) ; for ( ; i < w->d_func()->children.size(); ++i) { if(QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) { if(sibling->isVisible() && !sibling->isWindow()) { QRect siblingRect(ox+sibling->x(), oy+sibling->y(), sibling->width(), sibling->height()); if(siblingRect.intersects(q->rect())) r -= QRegion(siblingRect); } } } } return r;}void QWidgetPrivate::subtractOpaqueChildren(QRegion &rgn, const QRegion &clipRgn, const QPoint &offset) const{ for (int i=0; i < children.size(); ++i) { if (QWidget *child = qobject_cast<QWidget *>(children.at(i))) { if (child->isVisible() && !child->isWindow()) { QRegion childRgn = clipRgn & child->geometry().translated(offset); QWidgetPrivate *cd = child->d_func(); if (cd->extra && !cd->extra->mask.isEmpty()) childRgn &= cd->extra->mask.translated(offset + cd->data.crect.topLeft()); if (childRgn.isEmpty()) continue; if (cd->isOpaque()) rgn -= childRgn; else cd->subtractOpaqueChildren(rgn, childRgn, offset + child->geometry().topLeft()); } } }}bool QWidgetPrivate::hasBackground() const{ Q_Q(const QWidget); if (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_PaintOnScreen)) return true; if (q->testAttribute(Qt::WA_PaintOnScreen)) return true; if (!q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) { const QPalette &pal = q->palette(); QPalette::ColorRole bg = q->backgroundRole(); QBrush bgBrush = pal.brush(bg); return (bgBrush.style() != Qt::NoBrush && ((q->isWindow() || q->windowType() == Qt::SubWindow) || (QPalette::ColorRole(bg_role) != QPalette::NoRole || (pal.resolve() & (1<<bg))))); } return false;}void QWidgetPrivate::updateIsOpaque(){#ifdef Q_WS_MAC Q_Q(QWidget); extern void qt_mac_set_widget_is_opaque(QWidget*, bool); //qwidget_mac.cpp qt_mac_set_widget_is_opaque(q, isOpaque());#endif}bool QWidgetPrivate::isOpaque() const{ Q_Q(const QWidget);#ifdef Q_WS_X11 if (q->testAttribute(Qt::WA_X11OpenGLOverlay)) return false;#endif if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen) || q->testAttribute(Qt::WA_NoSystemBackground)) return true; if (!q->autoFillBackground()) return false; const QPalette &pal = q->palette(); QPalette::ColorRole bg = q->backgroundRole(); QBrush bgBrush = pal.brush(bg); return bgBrush.style() != Qt::NoBrush && bgBrush.isOpaque();}/*! \fn void QPixmap::fill(const QWidget *widget, const QPoint &offset) Fills the pixmap with the \a widget's background color or pixmap according to the given offset. The QPoint \a offset defines a point in widget coordinates to which the pixmap's top-left pixel will be mapped to. This is only significant if the widget has a background pixmap; otherwise the pixmap will simply be filled with the background color of the widget.*/void QPixmap::fill( const QWidget *widget, const QPoint &off ){ QPainter p(this); p.translate(-off); widget->d_func()->paintBackground(&p, QRect(off, size()));}void QWidgetPrivate::paintBackground(QPainter *painter, const QRect &rect, bool asRoot) const{#define FILL_RECT_WORKAROUND(painter, rect, brush) \ if (brush.style() == Qt::TexturePattern) \ painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); \ else \ painter->fillRect(rect, brush); Q_Q(const QWidget); const QBrush autoFillBrush = q->palette().brush(q->backgroundRole()); if (asRoot && !(q->autoFillBackground() && autoFillBrush.isOpaque())) { const QBrush bg = q->palette().brush(QPalette::Window);#ifdef Q_WS_QWS if (painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff)) painter->setCompositionMode(QPainter::CompositionMode_Source); //copy alpha straight in#endif FILL_RECT_WORKAROUND(painter, rect, bg); } if (q->autoFillBackground()) { FILL_RECT_WORKAROUND(painter, rect, autoFillBrush); }}/*! \internal This function is called when a widget is hidden or destroyed. It resets some application global pointers that should only refer active, visible widgets.*/void QWidgetPrivate::deactivateWidgetCleanup(){ Q_Q(QWidget); // If this was the active application window, reset it if (qApp->activeWindow() == q) qApp->setActiveWindow(0); // If the is the active mouse press widget, reset it#ifdef Q_WS_MAC extern QPointer<QWidget> qt_button_down;#else extern QWidget *qt_button_down;#endif if (q == qt_button_down) qt_button_down = 0;}/*! Returns a pointer to the widget with window identifer/handle \a id. The window identifier type depends on the underlying window system, see \c qwindowdefs.h for the actual definition. If there is no widget with this identifier, 0 is returned.*/QWidget *QWidget::find(WId id){ return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0;}/*! \fn WId QWidget::winId() const Returns the window system identifier of the widget. Portable in principle, but if you use it you are probably about to do something non-portable. Be careful. \sa find()*//*! Returns the GUI style for this widget \sa QWidget::setStyle(), QApplication::setStyle(), QApplication::style()*/QStyle *QWidget::style() const{ Q_D(const QWidget); if (d->extra && d->extra->style) return d->extra->style; return qApp->style();}/*! Sets the widget's GUI style to \a style. Ownership of the style object is not transferred. If no style is set, the widget uses the application's style, QApplication::style() instead. Setting a widget's style has no effect on existing or future child widgets. \warning This function is particularly useful for demonstration purposes, where you want to show Qt's styling capabilities. Real applications should avoid it and use one consistent GUI style instead. \sa style(), QStyle, QApplication::style(), QApplication::setStyle()*/void QWidget::setStyle(QStyle *style){ Q_D(QWidget); QStyle *old = QWidget::style(); d->createExtra(); d->extra->style = style; if (!(windowType() == Qt::Desktop) // (except desktop) && d->polished) { // (and have been polished) old->unpolish(this); QWidget::style()->polish(this); } QEvent e(QEvent::StyleChange); QApplication::sendEvent(this, &e);#ifdef QT3_SUPPORT styleChange(*old);#endif}#ifdef QT3_SUPPORT/*! \overload Sets the widget's GUI style to \a style using the QStyleFactory.*/QStyle* QWidget::setStyle(const QString &style){ QStyle *s = QStyleFactory::create(style); setStyle(s); return s;}#endif/*! \fn bool QWidget::isWindow() const Returns true if the widget is an independent window, otherwise returns false. A window is a widget that isn't visually the child of any other widget and that usually has a frame and a \l{QWidget::setWindowTitle()}{window title}. A window can have a \l{QWidget::parentWidget()}{parent widget}. It will then be grouped with its parent and deleted when the parent is deleted, minimized when the parent is minimized etc. If supported by the window manager, it will also have a common taskbar entry with its parent. QDialog and QMainWindow widgets are by default windows, even if a parent widget is specified in the constructor. This behavior is specified by the Qt::Window flag. \sa window(), isModal(), parentWidget()*//*! \property QWidget::modal \brief whether the widget is a modal widget This property only makes sense for windows. A modal widget prevents widgets in all other windows from getting any input. \sa isWindow(), windowModality, QDialog*//*! \property QWidget::windowModality \brief which windows are blocked by the modal widget \since 4.1 This property only makes sense for windows. A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must hide() the wiget first, then show() it again. By default, this property is Qt::NonModal. \sa isWindow(), QWidget::modal, QDialog*/Qt::WindowModality QWidget::windowModality() const{ return static_cast<Qt::WindowModality>(data->window_modality);}void QWidget::setWindowModality(Qt::WindowModality windowModality){ data->window_modality = windowModality; // setModal_sys() will be called by setAttribute() setAttribute(Qt::WA_ShowModal, (data->window_modality != Qt::NonModal));}/*! \fn bool QWidget::underMouse() const Returns true if the widget is under the mouse cursor; otherwise returns false. This value is not updated properly during drag and drop operations. \sa enterEvent(), leaveEvent()*//*! \property QWidget::minimized \brief whether this widget is minimized (iconified) This property is only relevant for windows. \sa showMinimized(), visible, show(), hide(), showNormal(), maximized*/bool QWidget::isMinimized() const{ return data->window_state & Qt::WindowMinimized; }/*! Shows the widget minimized, as an icon. Calling this function only affects \l{isWindow()}{windows}. \sa showNormal(), showMaximized(), show(), hide(), isVisible(), isMinimized()*/void QWidget::showMinimized(){ bool isMin = isMinimized(); if (isMin && isVisible()) return; ensurePolished();#ifdef QT3_SUPPORT if (parent()) QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);#endif if (!isMin) setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized); show();}/*! \property QWidget::maximized \brief whether this widget is maximized This property is only relevant for windows. Note that due to limitations in some window-systems, this does not always report the expected results (e.g. if the user on X11 maximizes the window via the window manager, Qt has no way of distinguishing this from any other resize). This is expected to improve as window manager protocols evolve. \sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized*/bool QWidget::isMaximized() const{ return data->window_state & Qt::WindowMaximized; }/*! Returns the current window state. The window state is a OR'ed combination of Qt::WindowState: Qt::WindowMinimized, Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -