Qt帮助文件使用方法

以为Qt 5.7 的Qt Widgets部件QLabel设置属性为例:

一、搜索关键字QLabel
Qt 5.7 Qt Widgets  C++ Classes  QLabel

显示出其为C++Classes类,是父类是Qt5的QtWidgets类?

QLabel Class描述:The QLabel widget provides a text or image display

该类内容:

Contents

其中该类属性:pixmap: QPixmap、setScaledContens:bool等等。。。

(1)以其中pixmap属性为例

该类的属性pixmap的类为QPixmap。那怎么用pixmap呢。点击这个属性名称,展开:

pixmap : QPixmap

(1.1) This property holds the label's pixmap.

If no pixmap has been set this will return 0.

Setting the pixmap clears any previous content. The buddy shortcut, if any, is disabled.

Access functions(访问函数):

 

const QPixmap *

pixmap() const

void

setPixmap(const QPixmap &)


const QPixmap *   pixmap() const   #先要定义一个QPixmap类型的变量。也就是把图片类型转成QPixmap型,才能为setPixmap所调用。

 

void setPixmap(const QPixmap &)  #setPixmap需要一个QPixmap类型的参数。

 

假设已经事先建立了QLabel类部件的一个名为label_pix的实例,那么label_pix也就拥有setPixmap的属性了。而这个属性需要一个QPixmap类型的参数。

QPixmap类型是什么呢,在Qt帮助文件里,点击QPixmap  链接,转到这个类怎么用。

(1.2) Qt 5.7  Qt GUI  C++ Classes  QPixmap

QPixmap Class:The QPixmap class is an off-screen image representation that can be used as a paint device.

其中它的Public Functions之一QPixmap有多种用法,可以定义图像尺寸,也可用于将指定的文件转成这种QPixmap类型。

QPixmap(const QString &fileName, const char *format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)

Constructs a pixmap from the file with the given fileName. If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap.

(1.3) 实际用法:

png=QtGui.QPixmap('c:/Users/administrator/Desktop/年度利润拆线图.png')  #调用QtGui.QPixmap方法,打开一个图片,存放在变量png中

self.label_pix.setPixmap(png)  # 在label_pix里面,调用setPixmap命令,建立一个图像存放框,并将之前的图像png存放在这个框里。 

(2)以其中setScaledContents属性为例

scaledContents : bool

说明:
This property holds whether the label will scale its contents to fill all available space.
When enabled and the label shows a pixmap, it will scale the pixmap to fill the available space.
This property's default is false.
Access functions:
bool hasScaledContents() const
void setScaledContents(bool)

属性的用法:self.label_pix.setScaledContents(True)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值