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

qtablewidget设置滚动条样式_word滚动条作用IhaveaQTabWidgetwithtoomanytabsandtheyoverflowwithscrollerarrows.Iwanttoincreasethewidthofthescrollerarrowsbymorethantwiceofthedefaultwidthsotheyareeasiertouseona…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

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

I have a QTabWidget with too many tabs

85f53f68e7e2cd2ed04607b6435f43aa.png

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

4a34e08ac14070fa9a7f5d8b0e942707.png

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.

e95bcdf0efe1659aacc4380094d5e2d8.png

解决方案

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.net/190426.html原文链接:https://javaforall.net

(0)
上一篇 2026年2月21日 上午7:43
下一篇 2026年2月21日 上午8:15


相关推荐

  • idea最新激活码2021(JetBrains全家桶)

    (idea最新激活码2021)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月26日
    110
  • C语言位运算之异或

    C语言位运算之异或运算符在任何一门编程语言中都占有不可磨灭的地位 今天我则要说一个运算符中的位运算中的异或 因为它不比其他运算符 也容易被我们忽视 但有时候他的作用还是蛮大的 下面我则以一道习题来和大家讨论一下异或这个运算符 例 一组数据中只有一个数字出现了一次 其他所有数字都是成对出现的 请找出这个数字 思路 乍一看 我也有点懵 看似简单的一道题 我却无从下手 但仔细想想我便想到了异或 它的规则如下 相同为

    2026年3月16日
    1
  • 中国程序员的悲哀

    中国程序员的悲哀
    中国程序员有个很悲哀的地方,大多数程序都对微软崇拜有加,奉若神明;然而大多数人都用着盗版的微软操作系统,盗版的visualstudio,然后还牛逼哄哄的出个什么微软vs使用心得。在他们眼里软件本身并不是商品,软件衍生出来的服务才能赚钱。
     
    这就好比几个小偷偷了别人的手机,然后交流用什么方法销赃才能最赚钱,你会觉得小偷太无耻了。但是如果满大街都是小偷,那你就会习以为常了。这么一想,发觉中国的程序员是抛开道德观念的,一心研究技术的。
     
    但是这不能怪程序员

    2022年10月9日
    4
  • 关闭令人抓狂的ESlint 语法检测配置方法

    关闭令人抓狂的ESlint 语法检测配置方法刚刚开始的小伙伴是不是空格报错少一行报错各种错?是不是觉得快被限制的失去了自由的思绪了?受折磨后找到了不错的文章来取消eslint语法检测限制,作为学习笔记摘自segmentfault其实我并不反对这些语法检测,但是像许多反个人意愿的那就真的不得不吐槽了,比如vue-cli脚手架创建的默认eslint规则:代码末尾不能加分号;代码中不能存在多行空行tab键

    2022年6月17日
    61
  • DDoS 分布式拒绝服务攻击

    DDoS 分布式拒绝服务攻击早上起来搜索了一下 github 在百度百科对 github 的事件报道中看到了 DDoS 大三时候学习计算机网络时 老师有讲到这个东西 当时听的似懂非懂 于是我点击进了 DDoS 的介绍 进行了进一步了解 特在此经行重点内容的简要记录 nbsp nbsp nbsp nbsp DDoS 分布式拒绝服务攻击 DistributeDe 是针对信息安全三要素 保密性 完整性 可用性 中的 可用性 进行攻击

    2026年3月18日
    2
  • OpenClaw国内免费部署教程 Molili轻松帮你拿下

    OpenClaw国内免费部署教程 Molili轻松帮你拿下

    2026年3月13日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号