📄 qframe.cpp
字号:
setAttribute(Qt::WA_WState_OwnSizePolicy, false); } d->frameStyle = (short)style; update(); d->updateFrameWidth(); d->oldFrameStyle = (short)style;}/*! \property QFrame::lineWidth \brief the line width Note that the \e total line width for frames used as separators (\l HLine and \l VLine) is specified by \l frameWidth. The default value is 1. \sa midLineWidth, frameWidth*/void QFrame::setLineWidth(int w){ Q_D(QFrame); if (short(w) == d->lineWidth) return; d->lineWidth = short(w); d->updateFrameWidth();}int QFrame::lineWidth() const{ Q_D(const QFrame); return d->lineWidth;}/*! \property QFrame::midLineWidth \brief the width of the mid-line The default value is 0. \sa lineWidth, frameWidth*/void QFrame::setMidLineWidth(int w){ Q_D(QFrame); if (short(w) == d->midLineWidth) return; d->midLineWidth = short(w); d->updateFrameWidth();}int QFrame::midLineWidth() const{ Q_D(const QFrame); return d->midLineWidth;}/*! \internal Updates the frame widths from the style.*/void QFramePrivate::updateStyledFrameWidths(){ Q_Q(const QFrame); QStyleOptionFrameV2 opt; opt.initFrom(q); QRect cr = q->style()->subElementRect(QStyle::SE_FrameContents, &opt, q); leftFrameWidth = cr.left() - opt.rect.left(); topFrameWidth = cr.top() - opt.rect.top(); rightFrameWidth = opt.rect.right() - cr.right(), bottomFrameWidth = opt.rect.bottom() - cr.bottom(); frameWidth = qMax(qMax(leftFrameWidth, rightFrameWidth), qMax(topFrameWidth, bottomFrameWidth));}/*! \internal Updated the frameWidth parameter.*/void QFramePrivate::updateFrameWidth(){ Q_Q(QFrame); QRect fr = q->frameRect(); int frameShape = frameStyle & QFrame::Shape_Mask; int frameShadow = frameStyle & QFrame::Shadow_Mask; frameWidth = -1; switch (frameShape) { case QFrame::NoFrame: frameWidth = 0; break; case QFrame::Box: case QFrame::HLine: case QFrame::VLine: switch (frameShadow) { case QFrame::Plain: frameWidth = lineWidth; break; case QFrame::Raised: case QFrame::Sunken: frameWidth = (short)(lineWidth*2 + midLineWidth); break; } break; case QFrame::StyledPanel: updateStyledFrameWidths(); break; case QFrame::WinPanel: frameWidth = 2; break; case QFrame::Panel: switch (frameShadow) { case QFrame::Plain: case QFrame::Raised: case QFrame::Sunken: frameWidth = lineWidth; break; } break; } if (frameWidth == -1) // invalid style frameWidth = 0; q->setFrameRect(fr); setLayoutItemMargins(QStyle::SE_FrameLayoutItem);}/*! \property QFrame::frameWidth \brief the width of the frame that is drawn. Note that the frame width depends on the \l{QFrame::setFrameStyle()}{frame style}, not only the line width and the mid-line width. For example, the style specified by \l NoFrame always has a frame width of 0, whereas the style \l Panel has a frame width equivalent to the line width. \sa lineWidth(), midLineWidth(), frameStyle()*/int QFrame::frameWidth() const{ Q_D(const QFrame); return d->frameWidth;}/*! \property QFrame::frameRect \brief the frame's rectangle The frame's rectangle is the rectangle the frame is drawn in. By default, this is the entire widget. Setting the rectangle does does \e not cause a widget update. The frame rectangle is automatically adjusted when the widget changes size. If you set the rectangle to a null rectangle (for example, QRect(0, 0, 0, 0)), then the resulting frame rectangle is equivalent to the \link QWidget::rect() widget rectangle\endlink.*/QRect QFrame::frameRect() const{ Q_D(const QFrame); QRect fr = contentsRect(); if ((d->oldFrameStyle & QFrame::Shape_Mask) == QFrame::StyledPanel) { fr.adjust(-d->leftFrameWidth, -d->topFrameWidth, d->rightFrameWidth, d->bottomFrameWidth); } else fr.adjust(-d->frameWidth, -d->frameWidth, d->frameWidth, d->frameWidth); return fr;}void QFrame::setFrameRect(const QRect &r){ Q_D(QFrame); QRect cr = r.isValid() ? r : rect(); if ((d->frameStyle & QFrame::Shape_Mask) == StyledPanel) { cr.adjust(d->leftFrameWidth, d->topFrameWidth, -d->rightFrameWidth, -d->bottomFrameWidth); } else cr.adjust(d->frameWidth, d->frameWidth, -d->frameWidth, -d->frameWidth); setContentsMargins(cr.left(), cr.top(), rect().right() - cr.right(), rect().bottom() - cr.bottom());}/*!\reimp*/QSize QFrame::sizeHint() const{ Q_D(const QFrame); // Returns a size hint for the frame - for HLine and VLine // shapes, this is stretchable one way and 3 pixels wide the // other. For other shapes, QWidget::sizeHint() is used. switch (d->frameStyle & Shape_Mask) { case HLine: return QSize(-1,3); case VLine: return QSize(3,-1); default: return QWidget::sizeHint(); }}/*!\reimp*/void QFrame::paintEvent(QPaintEvent *){ QPainter paint(this); drawFrame(&paint);}/*! \internal Mostly for the sake of Q3Frame */void QFrame::drawFrame(QPainter *p){ Q_D(QFrame); QPoint p1, p2; QStyleOptionFrame opt; opt.init(this); int frameShape = d->frameStyle & QFrame::Shape_Mask; int frameShadow = d->frameStyle & QFrame::Shadow_Mask; int lw = 0; int mlw = 0; opt.rect = frameRect(); switch (frameShape) { case QFrame::Box: case QFrame::HLine: case QFrame::VLine: case QFrame::StyledPanel: lw = d->lineWidth; mlw = d->midLineWidth; break; default: // most frame styles do not handle customized line and midline widths // (see updateFrameWidth()). lw = d->frameWidth; break; } opt.lineWidth = lw; opt.midLineWidth = mlw; if (frameShadow == Sunken) opt.state |= QStyle::State_Sunken; else if (frameShadow == Raised) opt.state |= QStyle::State_Raised; switch (frameShape) { case Box: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawShadeRect(p, opt.rect, opt.palette, frameShadow == Sunken, lw, mlw); break; case StyledPanel: style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this); break; case Panel: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawShadePanel(p, opt.rect, opt.palette, frameShadow == Sunken, lw); break; case WinPanel: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawWinPanel(p, opt.rect, opt.palette, frameShadow == Sunken); break; case HLine: case VLine: if (frameShape == HLine) { p1 = QPoint(opt.rect.x(), opt.rect.height() / 2); p2 = QPoint(opt.rect.x() + opt.rect.width(), p1.y()); } else { p1 = QPoint(opt.rect.x()+opt.rect.width() / 2, 0); p2 = QPoint(p1.x(), opt.rect.height()); } if (frameShadow == Plain) { QPen oldPen = p->pen(); p->setPen(QPen(opt.palette.foreground().color(), lw)); p->drawLine(p1, p2); p->setPen(oldPen); } else { qDrawShadeLine(p, p1, p2, opt.palette, frameShadow == Sunken, lw, mlw); } break; }}/*!\reimp */void QFrame::changeEvent(QEvent *ev){ Q_D(QFrame); if (ev->type() == QEvent::StyleChange#ifdef Q_WS_MAC || ev->type() == QEvent::MacSizeChange#endif ) d->updateFrameWidth(); QWidget::changeEvent(ev);}/*! \reimp */bool QFrame::event(QEvent *e){ if (e->type() == QEvent::ParentChange) d_func()->updateFrameWidth(); return QWidget::event(e);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -