QT几个小知识点总结

本文介绍了如何在QToolButton中设置图标大小和样式,使用QScreen和QImage捕获屏幕,以及如何在QLabel中实现外部网页和本地文件的链接功能。
摘要由CSDN通过智能技术生成

QToolButton设置图标及更改图标大小

    QToolButton btn;
    btn.setIconSize(QSize(35,35));//更改图标大小
    btn.setIcon(QIcon(":/images/screen.png"));//设置图标

QToolButton设置图标和文字显示格式

格式类型:

    enum ToolButtonStyle {
        ToolButtonIconOnly, //只显示图标(默认)
        ToolButtonTextOnly,//只显示文字
        ToolButtonTextBesideIcon,//文字在图标右侧
        ToolButtonTextUnderIcon,//文字在图标下面
        ToolButtonFollowStyle
    };
QToolButton btn;
btn.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

抓取整个屏幕

QScreen *screen = QGuiApplication::primaryScreen();
QImage image = screen->grabWindow(0,0,0,-1,-1).toImage();//第一个参数为0,表示主屏幕 

 QLabel实现外部网页和本地路径超链接

外部网页链接

QLabel *label = new  QLabel(this);
label->setOpenExternalLinks(true);
label->setText("<a style='color:blue; text-decoration: none' href = https://www.baidu.com>百度");//文字颜色为蓝色,无下划线

本地文件夹或者文件链接

链接前面加上file:///协议,解决本地路径中含有中文而访问失败的问题。

QLabel *label = new  QLabel(this);
label->setOpenExternalLinks(true);
label->setText("<a href=\"file:///D:/images/11.jpg\">打开图片");  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

视图猿人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值