前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >qtablewidget设置滚动条样式_word滚动条作用

qtablewidget设置滚动条样式_word滚动条作用

作者头像
全栈程序员站长
发布2022-11-09 13:43:17
发布2022-11-09 13:43:17
3.7K0
举报

大家好,又见面了,我是你们的朋友全栈君。

I have a QTabWidget with too many tabs

and they overflow with scroller arrows. I want to increase the width of the scroller arrows by more than twice of the default width so they are easier to use on a touchscreen.

There is a QTabWidget StyleSheet example but I cannot seem to get it to work nicely. The stylesheet below produces this screenshot

QTabBar::scroller { /* the width of the scroll buttons */

width: 40px;

}

QTabBar QToolButton { /* the scroll buttons are tool buttons */

width: 15px;

border-width: 2px;

}

where I would like something like this screenshot I edited.

解决方案

Method #1: This appears to be a bug, plain and simple. The background of the buttons is transparent; but setting it to white via a style sheet and setting the widths aren’t working right either.

I was able to solve the problem by using a style sheet thus:

QTabBar::scroller {width: 0px;}

If it don’t work: get rid of it. Then, I created two buttons with which to scroll it right, and laid the tab widget and buttons out horizontally. I set the padding of enclosing vertical and horizontal layouts to zero. I labelled the buttons “”, but u can git fancier if u want. If you want to have the tab area below the scroll bar the same width as the tab bar and the buttons, you need two tab widgets:

QTabWidget1 Button1 Button2

Wider QTabwidget2

Then, you set the height of QTabWidget1 so only the tabs show, and set QTabWidget2’s tab bar height to 0 with a stylesheet:

QTabBar::tab {height: 0px;}

so only the bodies of the tabs show; not the tabs themselves.

Since they aren’t thoughtful enough to expose a scroll method for the tab bar, you can fudge it by just changing the active tab via setCurrentIndex(); and it will stay in view.

You can then activate or de-activate the < and > buttons, depending on if the first or the last tab is already active. I’m not bothering to hide them nor disable them, since my app is mostly calculation and little polish.

Yes, it’s a PITA. If there’s no better way around it, just code around it. If life hands you a lemon, make lemon bombs, and show it who’s boss. (Actually, almost always figuratively, only.) I’ll submit a bug report one of these days, when I get time.

Maybe there are magic propert(ies) that can get those buttons to have normal backgrounds and sizes; but I don’t know them.

Edit: Method #2: Solved my problem, but won’t OP’s (for those experiencing the same problem. I came here because of this problem when I wasn’t trying to restyle these buttons. This is a known bug when using a stylesheet that a QTabBar either has or inherits: “When adding a style sheet to the tabs the navigation scroll arrow buttons become transparent”. (Vote for this issue, and it’ll get fixed faster.) Simply doing without the stylesheet solved my problem. Mine was on the parent form; and removing it and applying it to the element I wanted styled only, fixed it.

Method #3: You might try setting such properties as button width using non-stylesheet properties until it gets fixed; although I believe it’ll mean subclassing the QTabWidget and QTabBar to access the QToolButton properties. It sounds worse than it is. You might can accomplish it with about a dozen lines of code in the header; although if you use Qt Creator in the Design tab, or Designer, you’ll need to promote the tab widget.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/190426.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年9月23日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档