查看完整版本: [-- QLabel有没有一个属性,在setText以后自适应改变尺寸,不用每次调用adjustSize的? --]

QTCN开发网 -> Qt基础编程 -> QLabel有没有一个属性,在setText以后自适应改变尺寸,不用每次调用adjustSize的? [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

ustone 2018-05-20 10:19

QLabel有没有一个属性,在setText以后自适应改变尺寸,不用每次调用adjustSize的?

QLabel有没有一个属性,在setText以后自适应改变尺寸,不用每次调用adjustSize的?

liudianwu 2018-05-20 14:07
不是已经有adjustSize,还想怎样?

ustone 2018-05-20 21:51
liudianwu:不是已经有adjustSize,还想怎样?[表情]  (2018-05-20 14:07) 

如果只设置一次,以后setText以后自适应改变尺寸,感觉更简练。

kaon 2018-05-21 12:53
自己封装一下咯

ustone 2018-05-21 13:05
kaon:自己封装一下咯 (2018-05-21 12:53) 

那就划不着了

kaon 2018-05-21 18:28
https://stackoverflow.com/questions/13994902/how-do-i-get-a-qlabel-to-expand-to-full-width
看下这个

ustone 2018-05-22 06:10
kaon:https://stackoverflow.com/questions/13994902/how-do-i-get-a-qlabel-to-expand-to-full-width
看下这个 (2018-05-21 18:28) 

他说的是full width,我要的是最紧凑的width,因为我的label设置了背景色,长了不好看。

songhuirong1 2018-05-22 10:49
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)

ustone 2018-05-22 18:20
songhuirong1: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 funct .. (2018-05-22 10:49) 

谢谢,这个是显示图片而且自动缩放图片的,我想要的是显示字符串,而且自动调整width以刚好容纳字符串。

llwj0303 2020-08-06 11:10
l楼主最后解决了吗,遇到同样的问题


查看完整版本: [-- QLabel有没有一个属性,在setText以后自适应改变尺寸,不用每次调用adjustSize的? --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled