我有以下样式表:
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,
stop: 0 #2A2A2A, stop: 0.4 #E1E1E1,
stop: 0.5 #E1E1E1, stop: 1.0 #2A2A2A);
background-image: url(:/metal_toolbar);
border-left: 1px solid #9B9B9B;
border-right: 1px solid #9B9B9B;
border-bottom: 1px solid #9B9B9B;
border-top-color: #5A5A5A;
font: bold 12pt;
/*min-width: 20ex;
max-width: 1000ex;*/
padding: 2px;
}
如果我未在样式表中声明字体,则选项卡的大小将根据其包含的文本进行调整,但是,当我增加字体大小时,选项卡的大小将保持不变,并且文本会被截断。我已经尝试了所有宽度设置,但是我希望选项卡的宽度能够缩放到它包含的内容。
有人知道解决方法或解决方法吗?
我将样式表文件作为皮肤加载到程序中,因此,如果存在程序设计解决方案,则我更喜欢样式表解决方案
编辑:
这是具有适当标签尺寸的工作版本
QTabBar
{
font: bold 9pt;
}
QTabBar::tab
{
background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,
stop: 0 #2A2A2A, stop: 0.4 #E1E1E1,
stop: 0.5 #E1E1E1, stop: 1.0 #2A2A2A);
background-image: url(:/metal_toolbar);
border-left: 1px solid #9B9B9B;
border-right: 1px solid #9B9B9B;
border-bottom: 1px solid #9B9B9B;
border-top-color: #5A5A5A;
min-width: 20ex;
padding: 2px;
}
最佳答案
然后从QTabBar设置字体。下面是粗糙的伪代码。
font = tabbar.font()
font.setPointSize(12)
font.setBold(true)
tabbar.setFont(font)
您应该能够从QTabWidget访问QTabBar,并且只设置样式表而不使用字体。希望对您有所帮助。
关于c++ - QTabBar选项卡的大小不能随样式表字体缩放,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26045252/