Qt常用类——QFrame类与QWidge类

时间:2023-03-09 16:55:32
Qt常用类——QFrame类与QWidge类

QFrame与QWidget的区别:

QFrame是基本控件的基类,QWidget是QFrame基类。

QWidget类是所有用户界面对象的基类。

  Widget是用户界面的基本单元:它从窗口系统接收鼠标,键盘和其他事件,并在屏幕上绘制自己。

  每个Widget都是矩形的,它们按照Z-order进行排序。

QFrame类:

1.公有类型

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

2.属性

frameRect : QRect//控件矩形
frameWidth : const int//框架的宽度
frameShadow : Shadow//有无阴影
lineWidth : int//线宽度
frameShape : Shape//框架形状
midLineWidth : int//中间线的宽度

3.公有函数

QFrame(QWidget * parent = 0, Qt::WindowFlags f = 0)//构造函数,设置主窗口和框架类型
~QFrame()//析构函数
QRect frameRect() const//返回   框架的rect Shadow frameShadow() const
Shape frameShape() const int QFrame::frameStyle() const//返回框架风格,类似frameShadow()
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)

3.重写公有函数

virtual QSize sizeHint() const//返回尺寸大小

4.保护函数

void initStyleOption(QStyleOptionFrame * option) const//初始化画一个框架

5.公有保护函数

virtual void changeEvent(QEvent * ev)//事件状态改变

virtual bool event(QEvent * e)//接收事件

virtual void paintEvent(QPaintEvent *)//重绘事件