QFrame Class

QFrame 是一个具有边框的基类widget. 更多...

头文件: #include <QFrame>
qmake: QT += widgets
基类: QWidget
派生类:

QAbstractScrollArea, QLabel, QLCDNumber, QSplitter, QStackedWidget, and QToolBox

公有类型

enum Shadow { Plain, Raised, Sunken }
enum Shape { NoFrame, Box, Panel, StyledPanel, ..., WinPanel }
enum StyleMask { Shadow_Mask, Shape_Mask }

属性

公有函数

QFrame(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())
~QFrame()
QRect frameRect() const
Shadow frameShadow() const
Shape frameShape() const
int frameStyle() const
int frameWidth() const
int lineWidth() const
int midLineWidth() const
void setFrameRect(const QRect &)
void setFrameShadow(Shadow)
void setFrameShape(Shape)
void setFrameStyle(int style)
void setLineWidth(int)
void setMidLineWidth(int)

重新实现的公有函数

virtual QSize sizeHint() const

受保护的函数

void initStyleOption(QStyleOptionFrame *option) const

重新实现的受保护函数

virtual void changeEvent(QEvent *ev)
virtual bool event(QEvent *e)
virtual void paintEvent(QPaintEvent *)
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice

其他继承的成员

  • 19 个公有槽函数继承自 QWidget
  • 1 个公有槽函数继承自 QObject
  • 3 个信号继承自 QWidget
  • 2 个信号继承自 QObject
  • 1 个公有变量继承自 QObject
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject
  • 1 个受保护的槽函数继承自 QWidget
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

QFrame 是一个具有边框的基类widget.

QMenu 使用这个特性将菜单 "提升" 到周围屏幕上方. QProgressBar 显示 "凹陷" 外观. QLabel 显示扁平外观. 这类widget的边框支持更改.


  QLabel label(...);
  label.setFrameStyle(QFrame::Panel | QFrame::Raised);
  label.setLineWidth(2);

  QProgressBar pbar(...);
  label.setFrameStyle(QFrame::NoFrame);

QFrame 也支持创建没有任何内容的占位边框.

边框样式通过 边框形状阴影样式 设定, 阴影样式可以在视觉上将边框与周围widget分隔. 这些属性可以调用 setFrameStyle() 函数设置, 调用 frameStyle() 获取.

边框形状有 NoFrame, Box, Panel, StyledPanel, HLine, VLine; 阴影样式有 Plain, Raised, Sunken.

边框widget有三个描述边线粗细的属性: lineWidth, midLineWidth, frameWidth.

  • lineWidth: 边线宽度.
  • midLineWidth: 边框中部额外线条的宽度, 这个线条使用另外颜色显示3D效果. 注意: 只有凸起或凹陷的 Box, HLineVLine 边框才会绘制中线.
  • frameWidth: 边框宽度, 由边框样式决定, 调用 frameWidth() 获取边框样式设定的值.

调用 QWidget::setContentsMargins() 设置外边距.

下表展示不同样式和线宽组合效果:

Table of frame styles

成员类型

enum QFrame::Shadow

This enum type defines the types of shadow that are used to give a 3D effect to frames.

ConstantValueDescription
QFrame::Plain0x0010the frame and contents appear level with the surroundings; draws using the palette QPalette::WindowText color (without any 3D effect)
QFrame::Raised0x0020the frame and contents appear raised; draws a 3D raised line using the light and dark colors of the current color group
QFrame::Sunken0x0030the frame and contents appear sunken; draws a 3D sunken line using the light and dark colors of the current color group

Shadow interacts with QFrame::Shape, the lineWidth() and the midLineWidth(). See the picture of the frames in the main class documentation.

参见 QFrame::Shape, lineWidth(), and midLineWidth().

enum QFrame::Shape

This enum type defines the shapes of frame available.

ConstantValueDescription
QFrame::NoFrame0QFrame draws nothing
QFrame::Box0x0001QFrame draws a box around its contents
QFrame::Panel0x0002QFrame draws a panel to make the contents appear raised or sunken
QFrame::StyledPanel0x0006draws a rectangular panel with a look that depends on the current GUI style. It can be raised or sunken.
QFrame::HLine0x0004QFrame draws a horizontal line that frames nothing (useful as separator)
QFrame::VLine0x0005QFrame draws a vertical line that frames nothing (useful as separator)
QFrame::WinPanel0x0003draws a rectangular panel that can be raised or sunken like those in Windows 2000. Specifying this shape sets the line width to 2 pixels. WinPanel is provided for compatibility. For GUI style independence we recommend using StyledPanel instead.

When it does not call QStyle, Shape interacts with QFrame::Shadow, the lineWidth() and the midLineWidth() to create the total result. See the picture of the frames in the main class documentation.

参见 QFrame::Shadow, QFrame::style(), and QStyle::drawPrimitive().

enum QFrame::StyleMask

This enum defines two constants that can be used to extract the two components of frameStyle():

ConstantValueDescription
QFrame::Shadow_Mask0x00f0The Shadow part of frameStyle()
QFrame::Shape_Mask0x000fThe Shape part of frameStyle()

Normally, you don't need to use these, since frameShadow() and frameShape() already extract the Shadow and the Shape parts of frameStyle().

参见 frameStyle() and setFrameStyle().

属性

frameRect : QRect

This property holds 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 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 widget rectangle.

访问函数:

QRect frameRect() const
void setFrameRect(const QRect &)

frameShadow : Shadow

This property holds the frame shadow value from the frame style

访问函数:

Shadow frameShadow() const
void setFrameShadow(Shadow)

参见 frameStyle() and frameShape().

frameShape : Shape

This property holds the frame shape value from the frame style

访问函数:

Shape frameShape() const
void setFrameShape(Shape)

参见 frameStyle() and frameShadow().

frameWidth : const int

This property holds the width of the frame that is drawn.

Note that the frame width depends on the frame style, not only the line width and the mid-line width. For example, the style specified by NoFrame always has a frame width of 0, whereas the style Panel has a frame width equivalent to the line width.

访问函数:

int frameWidth() const

参见 lineWidth(), midLineWidth(), and frameStyle().

lineWidth : int

This property holds the line width

Note that the total line width for frames used as separators (HLine and VLine) is specified by frameWidth.

The default value is 1.

访问函数:

int lineWidth() const
void setLineWidth(int)

参见 midLineWidth and frameWidth.

midLineWidth : int

This property holds the width of the mid-line

The default value is 0.

访问函数:

int midLineWidth() const
void setMidLineWidth(int)

参见 lineWidth and frameWidth.

成员函数

QFrame::QFrame(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())

Constructs a frame widget with frame style NoFrame and a 1-pixel frame width.

The parent and f arguments are passed to the QWidget constructor.

QFrame::~QFrame()

Destroys the frame.

[virtual protected] void QFrame::changeEvent(QEvent *ev)

重新实现 QWidget::changeEvent().

[virtual protected] bool QFrame::event(QEvent *e)

重新实现 QObject::event().

int QFrame::frameStyle() const

Returns the frame style.

The default value is QFrame::Plain.

参见 setFrameStyle(), frameShape(), and frameShadow().

[protected] void QFrame::initStyleOption(QStyleOptionFrame *option) const

Initializes option with the values from this QFrame. This method is useful for subclasses when they need a QStyleOptionFrame but don't want to fill in all the information themselves.

This function was introduced in Qt 5.5.

参见 QStyleOption::initFrom().

[virtual protected] void QFrame::paintEvent(QPaintEvent *)

重新实现 QWidget::paintEvent().

void QFrame::setFrameStyle(int style)

Sets the frame style to style.

The style is the bitwise OR between a frame shape and a frame shadow style. See the picture of the frames in the main class documentation.

The frame shapes are given in QFrame::Shape and the shadow styles in QFrame::Shadow.

If a mid-line width greater than 0 is specified, an additional line is drawn for Raised or Sunken Box, HLine, and VLine frames. The mid-color of the current color group is used for drawing middle lines.

参见 frameStyle().

[virtual] QSize QFrame::sizeHint() const

重新实现 QWidget::sizeHint().