QFrame 类

QFrame 类是可以拥有框架的 Widget 基类。 更多...

头: #include <QFrame>
qmake: QT += widgets
继承: QWidget
继承者:

QAbstractScrollArea , QLabel , QLCDNumber , QSplitter , QStackedWidget ,和 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
形状 frameShape () const
int frameStyle () const
int frameWidth () const
int lineWidth () const
int midLineWidth () const
void setFrameRect ( const QRect & )
void setFrameShadow ( Shadow )
void setFrameShape ( 形状 )
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 * )

额外继承成员

详细描述

QFrame 类是可以拥有框架的 Widget 基类。

QMenu 使用此 Raise (凸起) 菜单在周围屏幕上方。 QProgressBar 拥有 Sunken (凹陷) 外观。 QLabel 拥有 Flat (扁平) 外观。像这些的 Widget 框架可以改变。

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

QFrame class can also be used directly for creating simple placeholder frames without any contents.

框架样式的指定通过 框架形状 阴影样式 用于在视觉上分隔框架与周围 Widget。这些特性可以一起设置使用 setFrameStyle () 函数和读取采用 frameStyle ().

框架形状包括 NoFrame , Box , Panel , StyledPanel , HLine and VLine ;阴影样式包括 Plain , Raised and Sunken .

框架 Widget 拥有 3 个描述边框厚度的属性: lineWidth , midLineWidth ,和 frameWidth .

  • 线宽是框架边框的宽度。可以修改它以自定义框架外观。
  • 中线宽度指定框架中间额外线条的宽度,使用第 3 种颜色以获得特殊 3D 效果。注意:只绘制中线对于 Box , HLine and VLine 凸起或凹陷框架。
  • 框架宽度由框架样式确定,和 frameWidth () 函数用于获取由所用样式定义的值。

定制框架和框架内容之间的边距采用 QWidget::setContentsMargins () 函数。

此表展示一些样式和线宽的组合:

Table of frame styles

成员类型文档编制

enum QFrame:: Shadow

此枚举类型定义用于把 3D 效果给予框架的阴影类型。

常量 描述
QFrame::Plain 0x0010 the frame and contents appear level with the surroundings; draws using the palette QPalette::WindowText color (without any 3D effect)
QFrame::Raised 0x0020 the frame and contents appear raised; draws a 3D raised line using the light and dark colors of the current color group
QFrame::Sunken 0x0030 the frame and contents appear sunken; draws a 3D sunken line using the light and dark colors of the current color group

阴影交互影响 QFrame::Shape lineWidth () 和 midLineWidth ()。见主类文档编制框架图片。

另请参阅 QFrame::Shape , lineWidth (),和 midLineWidth ().

enum QFrame:: Shape

此枚举类型定义框架可用形状。

常量 描述
QFrame::NoFrame 0 QFrame 什么都不绘制
QFrame::Box 0x0001 QFrame 在其内容周围绘制方框
QFrame::Panel 0x0002 QFrame 绘制平面以使内容看起来凸起 (或凹陷)
QFrame::StyledPanel 0x0006 绘制外观从属当前 GUI 样式的矩形面板。可以凸起或凹陷。
QFrame::HLine 0x0004 QFrame 绘制无边框水平线 (作为分隔符很有用)
QFrame::VLine 0x0005 QFrame 绘制无边框垂直线 (作为分隔符很有用)
QFrame::WinPanel 0x0003 绘制可以像 Windows 2000 那些凸起或凹陷的矩形面板。指定此形状设置线宽为 2 像素。提供 WinPanel 是为了兼容性。对于独立 GUI 样式,推荐使用 StyledPanel 代替。

当不调用 QStyle ,形状交互影响 QFrame::Shadow lineWidth () 和 midLineWidth () 以创建总结果。见主类文档编制框架图片。

另请参阅 QFrame::Shadow , QFrame::style (),和 QStyle::drawPrimitive ().

enum QFrame:: StyleMask

此枚举定义 2 常量,可以用于提取 2 分量为 frameStyle ():

常量 描述
QFrame::Shadow_Mask 0x00f0 Shadow 部分在 frameStyle ()
QFrame::Shape_Mask 0x000f Shape 部分在 frameStyle ()

通常,不需要使用这些,由于 frameShadow () 和 frameShape () 已提取 Shadow Shape 部分在 frameStyle ().

另请参阅 frameStyle () 和 setFrameStyle ().

特性文档编制

frameRect : QRect

此特性保持框架的矩形

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.

若将矩形设为 null 矩形 (例如, QRect (0, 0, 0, 0)), then the resulting frame rectangle is equivalent to the 小部件矩形 .

访问函数:

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

frameShadow : Shadow

此特性保持来自框架样式的框架阴影值

访问函数:

Shadow frameShadow () const
void setFrameShadow ( Shadow )

另请参阅 frameStyle () 和 frameShape ().

frameShape : Shape

此特性保持来自框架样式的框架形状值

访问函数:

形状 frameShape () const
void setFrameShape ( 形状 )

另请参阅 frameStyle () 和 frameShadow ().

frameWidth : const int

此特性保持绘制框架的宽度。

注意:框架宽度从属 框架样式 ,不只线宽和中线宽。例如,样式指定通过 NoFrame 始终拥有 0 宽框架,而样式 Panel 拥有的框架宽度等于线宽。

访问函数:

int frameWidth () const

另请参阅 lineWidth (), midLineWidth (),和 frameStyle ().

lineWidth : int

此特性保持线宽

注意, total 线宽为框架用作分隔符 ( HLine and VLine ) 指定通过 frameWidth .

默认值为 1。

访问函数:

int lineWidth () const
void setLineWidth ( int )

另请参阅 midLineWidth and frameWidth .

midLineWidth : int

此特性保持中线宽度

默认值为 0。

访问函数:

int midLineWidth () const
void setMidLineWidth ( int )

另请参阅 lineWidth and frameWidth .

成员函数文档编制

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

构造框架 Widget 采用框架样式 NoFrame 和 1 像素框架宽度。

parent and f 自变量被传递给 QWidget 构造函数。

QFrame:: ~QFrame ()

销毁框架。

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

重实现自 QWidget::changeEvent ().

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

重实现自 QObject::event ().

int QFrame:: frameStyle () const

返回框架样式。

默认值为 QFrame::Plain .

另请参阅 setFrameStyle (), frameShape (),和 frameShadow ().

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

初始化 option 采用值来自此 QFrame 。此方法对子类是有用的,当需要 QStyleOptionFrame 但不希望自己填充所有信息。

该函数在 Qt 5.5 引入。

另请参阅 QStyleOption::initFrom ().

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

重实现自 QWidget::paintEvent ().

void QFrame:: setFrameStyle ( int style )

将框架样式设为 style .

style 是框架形状和框架阴影样式之间的按位 OR。见主类文档编制中的框架图片。

框架形状给出在 QFrame::Shape 和阴影样式在 QFrame::Shadow .

若指定大于 0 的中线宽度,则绘制附加线条为 Raised or Sunken Box , HLine ,和 VLine 框架。使用当前颜色组的中间色绘制中间线条。

另请参阅 frameStyle ().

[virtual] QSize QFrame:: sizeHint () const

重实现自 QWidget::sizeHint ().