QTabWidget increase tab scroller arrow button width

和自甴很熟 提交于 2019-12-04 21:51:43

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 "<" and ">", 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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!