📄 qwidget.cpp
字号:
void QWidgetPrivate::subtractOpaqueSiblings(QRegion &rgn, const QPoint &offset) const{ static int disableSubtractOpaqueSiblings = qgetenv("QT_NO_SUBTRACTOPAQUESIBLINGS").toInt(); if (disableSubtractOpaqueSiblings) return; Q_Q(const QWidget); if (q->isWindow()) return; QPoint myOffset = offset - q->data->crect.topLeft(); const QWidgetPrivate *pd = q->parentWidget()->d_func(); pd->subtractOpaqueSiblings(rgn, myOffset); int idx = pd->children.indexOf(const_cast<QWidget*>(q)) + 1; // argh, list<QObject*> is not compatible with const QObject* pd->subtractOpaqueChildren(rgn, q->rect(), myOffset, idx);}#endif // Q_WIDGET_CACHE_OPAQUEREGIONSbool 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 macUpdateIsOpaque();#endif#ifdef Q_WIDGET_CACHE_OPAQUEREGIONS // hw: todo: only needed if opacity actually changed setDirtyOpaqueRegion();#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)) return true; const QPalette &pal = q->palette(); if (q->autoFillBackground()) { const QBrush &autoFillBrush = pal.brush(q->backgroundRole()); if (autoFillBrush.style() != Qt::NoBrush && autoFillBrush.isOpaque()) { return true; } } if (q->isWindow() && !q->testAttribute(Qt::WA_NoSystemBackground)) { const QBrush &windowBrush = q->palette().brush(QPalette::Window); if (windowBrush.style() != Qt::NoBrush && windowBrush.isOpaque()) return true; } return false;}/*! \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); } if (q->testAttribute(Qt::WA_StyledBackground)) { QStyleOption opt; opt.initFrom(q); q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q); }}/*! \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::internalWinId() const \internal Returns the window system identifier of the widget, or 0 if the widget is not created yet.*//*! \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()*/WId QWidget::winId() const{ if (!testAttribute(Qt::WA_WState_Created)) { QWidget *that = const_cast<QWidget*>(this); that->d_func()->createWinId(); return that->data->winid; } return data->winid;}void QWidgetPrivate::createWinId(WId winid){ Q_Q(QWidget); if (!q->testAttribute(Qt::WA_WState_Created)) { if (!q->isWindow()) { QWidgetPrivate *pd = q->parentWidget()->d_func(); if (!q->parentWidget()->testAttribute(Qt::WA_WState_Created)) pd->createWinId(); for (int i = 0; i < pd->children.size(); ++i) { QWidget *w = qobject_cast<QWidget *>(pd->children.at(i)); if (w && !w->isWindow() && !w->testAttribute(Qt::WA_WState_Created)) if (w!=q) { w->create(); } else { w->create(winid); // if the window has already been created, we // need to raise it to its proper stacking position if (winid) w->raise(); } } } else { q->create(); } }}/*!\internalEnsures that the widget has a window system identifier, i.e. that it is known to the windowing system.*/void QWidget::createWinId(){ Q_D(QWidget);// qWarning("QWidget::createWinId is obsolete, please fix your code."); d->createWinId();}#ifndef QT_NO_STYLE_STYLESHEET/*! \property QWidget::styleSheet \brief the widget's style sheet \since 4.2 The style sheet contains a textual description of customizations to the widget's style, as described in the \l{Qt Style Sheets} document. \note Qt style sheets are currently not supported for QMacStyle (the default style on Mac OS X). We plan to address this in some future release. \sa setStyle(), QApplication::styleSheet, {Qt Style Sheets}*/QString QWidget::styleSheet() const{ Q_D(const QWidget); if (!d->extra) return QString(); return d->extra->styleSheet;}void QWidget::setStyleSheet(const QString& styleSheet){ Q_D(QWidget); d->createExtra(); QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(d->extra->style); d->extra->styleSheet = styleSheet; if (styleSheet.isEmpty()) { // stylesheet removed if (!proxy) return; d->inheritStyle(); return; } if (proxy) { // style sheet update proxy->repolish(this); return; } if (testAttribute(Qt::WA_SetStyle)) { d->setStyle_helper(new QStyleSheetStyle(d->extra->style), true); } else { d->setStyle_helper(new QStyleSheetStyle(0), true); }}#endif // QT_NO_STYLE_STYLESHEET/*! \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. The 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); setAttribute(Qt::WA_SetStyle, style != 0); d->createExtra();#ifndef QT_NO_STYLE_STYLESHEET // if we have an application stylesheet or have a proxy already, propagate if (qobject_cast<QStyleSheetStyle *>(d->extra->style) || !qApp->styleSheet().isEmpty()) d->setStyle_helper(new QStyleSheetStyle(style), true); else#endif d->setStyle_helper(style, false);}void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate, bool#ifdef Q_WS_MAC metalHack#endif ){ Q_Q(QWidget); createExtra(); QStyle *oldStyle = q->style();#ifndef QT_NO_STYLE_STYLESHEET QStyle *origStyle = extra->style;#endif extra->style = newStyle; // repolish if (q->windowType() != Qt::Desktop) { if (polished) { oldStyle->unpolish(q);#ifdef Q_WS_MAC if (metalHack) macUpdateMetalAttribute();#endif q->style()->polish(q);#ifdef Q_WS_MAC } else if (metalHack) { macUpdateMetalAttribute();#endif } } if (propagate) { for (int i = 0; i < children.size(); ++i) { QWidget *c = qobject_cast<QWidget*>(children.at(i)); if (c) c->d_func()->inheritStyle(); } } QEvent e(QEvent::StyleChange); QApplication::sendEvent(q, &e);#ifdef QT3_SUPPORT q->styleChange(*oldStyle);#endif#ifndef QT_NO_STYLE_STYLESHEET // dereference the old stylesheet style if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(origStyle)) proxy->deref();#endif}// Inherits style from the current parent and propagates it as necessaryvoid QWidgetPrivate::inheritStyle(){#ifndef QT_NO_STYLE_STYLESHEET Q_Q(QWidget); QStyleSheetStyle *proxy = extra ? qobject_cast<QStyleSheetStyle *>(extra->style) : 0; if (!q->styleSheet().isEmpty()) { Q_ASSERT(proxy); proxy->repolish(q); return; } QStyle *origStyle = proxy ? proxy->base : (extra ? (QStyle*)extra->style : 0); QWidget *parent = q->parentWidget(); QStyle *parentStyle = (parent && parent->d_func()->extra) ? (QStyle*)parent->d_func()->extra->style : 0; // If we have stylesheet on app or parent has stylesheet style, we need // to b
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -