📄 qdrawutil.cpp
字号:
p->drawLines(lines); if (fill) // fill with fill color p->fillRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, *fill); p->setPen(oldPen); // restore pen}/*! \internal This function draws a rectangle with two pixel line width. It is called from qDrawWinButton() and qDrawWinPanel(). c1..c4 and fill are used: 1 1 1 1 1 2 1 3 3 3 4 2 1 3 F F 4 2 1 3 F F 4 2 1 4 4 4 4 2 2 2 2 2 2 2*/static void qDrawWinShades(QPainter *p, int x, int y, int w, int h, const QColor &c1, const QColor &c2, const QColor &c3, const QColor &c4, const QBrush *fill){ if (w < 2 || h < 2) // can't do anything with that return; QPen oldPen = p->pen(); QPoint a[3] = { QPoint(x, y+h-2), QPoint(x, y), QPoint(x+w-2, y) }; p->setPen(c1); p->drawPolyline(a, 3); QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) }; p->setPen(c2); p->drawPolyline(b, 3); if (w > 4 && h > 4) { QPoint c[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) }; p->setPen(c3); p->drawPolyline(c, 3); QPoint d[3] = { QPoint(x+1, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y+1) }; p->setPen(c4); p->drawPolyline(d, 3); if (fill) p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill); } p->setPen(oldPen);}/*! \fn void qDrawWinButton(QPainter *painter, int x, int y, int width, int height, const QPalette &palette, bool sunken, const QBrush *fill) \relates QPainter Draws the Windows-style button specified by the given point (\a x, \a y}, \a width and \a height using the provided \a painter with a line width of 2 pixels. The button's interior is filled with the \a{fill} brush unless \a fill is 0. The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The button appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style()-> Use the drawing functions in QStyle to make widgets that follow the current GUI style. \sa qDrawWinPanel(), QStyle*/void qDrawWinButton(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill){ if (sunken) qDrawWinShades(p, x, y, w, h, pal.shadow().color(), pal.light().color(), pal.dark().color(), pal.button().color(), fill); else qDrawWinShades(p, x, y, w, h, pal.light().color(), pal.shadow().color(), pal.button().color(), pal.dark().color(), fill);}/*! \fn void qDrawWinPanel(QPainter *painter, int x, int y, int width, int height, const QPalette &palette, bool sunken, const QBrush *fill) \relates QPainter Draws the Windows-style panel specified by the given point(\a x, \a y), \a width and \a height using the provided \a painter with a line width of 2 pixels. The button's interior is filled with the \a fill brush unless \a fill is 0. The given \a palette specifies the shading colors. The panel appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style. Alternatively you can use a QFrame widget and apply the QFrame::setFrameStyle() function to display a shaded panel: \code QFrame frame: frame.setFrameStyle(QFrame::WinPanel | QFrame::Raised); \endcode \sa qDrawShadePanel(), qDrawWinButton(), QStyle*/void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill){ if (sunken) qDrawWinShades(p, x, y, w, h, pal.dark().color(), pal.light().color(), pal.shadow().color(), pal.midlight().color(), fill); else qDrawWinShades(p, x, y, w, h, pal.light().color(), pal.shadow().color(), pal.midlight().color(), pal.dark().color(), fill);}/*! \fn void qDrawPlainRect(QPainter *painter, int x, int y, int width, int height, const QColor &lineColor, int lineWidth, const QBrush *fill) \relates QPainter Draws the plain rectangle beginning at (\a x, \a y) with the given \a width and \a height, using the specified \a painter, \a lineColor and \a lineWidth. The rectangle's interior is filled with the \a fill brush unless \a fill is 0. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style. Alternatively you can use a QFrame widget and apply the QFrame::setFrameStyle() function to display a plain rectangle: \code QFrame frame: frame.setFrameStyle(QFrame::Box | QFrame::Plain); \endcode \sa qDrawShadeRect(), QStyle*/void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, int lineWidth, const QBrush *fill){ if (w == 0 || h == 0) return; if (!(w > 0 && h > 0 && lineWidth >= 0)) { qWarning("qDrawPlainRect: Invalid parameters"); } QPen oldPen = p->pen(); QBrush oldBrush = p->brush(); p->setPen(c); p->setBrush(Qt::NoBrush); for (int i=0; i<lineWidth; i++) p->drawRect(x+i, y+i, w-i*2 - 1, h-i*2 - 1); if (fill) { // fill with fill color p->setPen(Qt::NoPen); p->setBrush(*fill); p->drawRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2); } p->setPen(oldPen); p->setBrush(oldBrush);}/***************************************************************************** Overloaded functions. *****************************************************************************//*! \fn void qDrawShadeLine(QPainter *painter, const QPoint &p1, const QPoint &p2, const QPalette &palette, bool sunken, int lineWidth, int midLineWidth) \relates QPainter \overload Draws a horizontal or vertical shaded line between \a p1 and \a p2 using the given \a painter. Note that nothing is drawn if the line between the points would be neither horizontal nor vertical. The provided \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The given \a lineWidth specifies the line width for each of the lines; it is not the total line width. The given \a midLineWidth specifies the width of a middle line drawn in the QPalette::mid() color. The line appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style. Alternatively you can use a QFrame widget and apply the QFrame::setFrameStyle() function to display a shaded line: \code QFrame frame: frame.setFrameStyle(QFrame::HLine | QFrame::Sunken); \endcode \sa qDrawShadeRect(), qDrawShadePanel(), QStyle*/void qDrawShadeLine(QPainter *p, const QPoint &p1, const QPoint &p2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth){ qDrawShadeLine(p, p1.x(), p1.y(), p2.x(), p2.y(), pal, sunken, lineWidth, midLineWidth);}/*! \fn void qDrawShadeRect(QPainter *painter, const QRect &rect, const QPalette &palette, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill) \relates QPainter \overload Draws the shaded rectangle specified by \a rect using the given \a painter. The provide \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors. The given \a lineWidth specifies the line width for each of the lines; it is not the total line width. The \a midLineWidth specifies the width of a middle line drawn in the QPalette::mid() color. The rectangle's interior is filled with the \a fill brush unless \a fill is 0. The rectangle appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style. Alternatively you can use a QFrame widget and apply the QFrame::setFrameStyle() function to display a shaded rectangle: \code QFrame frame: frame.setFrameStyle(QFrame::Box | QFrame::Raised); \endcode \sa qDrawShadeLine(), qDrawShadePanel(), qDrawPlainRect(), QStyle*/void qDrawShadeRect(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill){ qDrawShadeRect(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, lineWidth, midLineWidth, fill);}/*! \fn void qDrawShadePanel(QPainter *painter, const QRect &rect, const QPalette &palette, bool sunken, int lineWidth, const QBrush *fill) \relates QPainter \overload Draws the shaded panel at the rectangle specified by \a rect using the given \a painter and the given \a lineWidth. The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The panel's interior is filled with the \a fill brush unless \a fill is 0. The panel appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style. Alternatively you can use a QFrame widget and apply the QFrame::setFrameStyle() function to display a shaded panel: \code QFrame frame: frame.setFrameStyle( QFrame::Panel | QFrame::Sunken); \endcode \sa qDrawWinPanel(), qDrawShadeLine(), qDrawShadeRect(), QStyle*/void qDrawShadePanel(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill){ qDrawShadePanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, lineWidth, fill);}/*! \fn void qDrawWinButton(QPainter *painter, const QRect &rect, const QPalette &palette, bool sunken, const QBrush *fill) \relates QPainter \overload Draws the Windows-style button at the rectangle specified by \a rect using the given \a painter with a line width of 2 pixels. The button's interior is filled with the \a{fill} brush unless \a fill is 0. The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The button appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style()-> Use the drawing functions in QStyle to make widgets that follow the current GUI style. \sa qDrawWinPanel(), QStyle*/void qDrawWinButton(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, const QBrush *fill){ qDrawWinButton(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);}/*! \fn void qDrawWinPanel(QPainter *painter, const QRect &rect, const QPalette &palette, bool sunken, const QBrush *fill) \overload Draws the Windows-style panel at the rectangle specified by \a rect using the given \a painter with a line width of 2 pixels. The button's interior is filled with the \a fill brush unless \a fill is 0. The given \a palette specifies the shading colors. The panel appears sunken if \a sunken is true, otherwise raised. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style. Alternatively you can use a QFrame widget and apply the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -