如何将图标添加到QTabWidget(不适用于每个选项卡)? [英] How to add an icon to a QTabWidget (not for each tab)?

查看:1178
本文介绍了如何将图标添加到QTabWidget(不适用于每个选项卡)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在QTabWidget的左上方添加一个图标.我不想为每个标签添加图标.如何使用样式表或以编程方式在C ++中做到这一点?

I would like to add an icon at the top left of the QTabWidget. I don't want to add an icon for each tab. How to do that using a stylesheet or programmatically in C++?

推荐答案

下面的样式表会将图像添加到所有标签的左侧,但不会添加到单个标签.但是,很有可能需要调整CSS中的其他属性以完善最终结果.

Stylesheet below will add an image to the left of all tabs, but not to individual tabs. However, it is very likely that you'll need to tweak other attributes in the CSS to polish the final result.

QTabWidget > QTabBar {
  background: url(url-to-your-corner-image);
  background-repeat: norepeat;
  margin-top: 10px; /* whatever needed to center the image vertically */
}
QTabWidget > QTabBar::tab:first {
  margin-left: 10px; /* at least the width of your image */
}

这篇关于如何将图标添加到QTabWidget(不适用于每个选项卡)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆