QSplitter 在 QWidget 和 QTabWidget 之间变得无法区分
我将 QWidget 和 QTabWidget 放在一个水平拆分器中并排放置。并且分离器失去了形状,只有将鼠标悬停在分离器上才能知道有分离器。如何让它可见?
谢谢。
I am puting a QWidget and a QTabWidget next to each other in one horisontal splitter. And the splitter loses it's shape, you can know that there is a splitter only by hovering mouse on it. How to make it visible?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
由于 QSplitterHandle(大多数人认为是“分割器”)是从 QWidget 派生的,因此您可以向其中添加其他小部件。以下是我过去为解决这个问题所做的操作:
这会在分离器手柄上添加一条下沉线。当然,您可以为框架
line
选择其他样式,或者使用完全不同的样式作为添加到分割器手柄的小部件。Since the QSplitterHandle (which is what most people think of as the 'splitter') is derived from QWidget, you can add other widgets to it. Here is what I have done to solve this exact problem in the past:
This adds a sunken line to the splitter handle. You can, of course, choose another style for the frame
line
or use something entirely different as the widget you add to the splitter handle.我基于上面的代码,但它处理两个分离器方向。
我只是更喜欢不透明的大小调整和不可折叠的子项。
握把由三条平行线组成。您可以调整手柄的宽度,但在 Windows 上,握把 7 看起来不错;还没有在 Linux 或 Mac 上检查过。
I based this on the above code but it handles both splitter orientations.
I just preferred non-opaque resizing and non-collapsible children.
The grip consists of three parallel lines. You can play with the handle width, but grip at 7 looks good on Windows; haven't checked in Linux or Mac.
对于每个拆分器来说都是如此,至少对于 WinXP 和默认的 Luna 主题(更改为经典可以解决问题)。
如果您想继续使用 Luna,您可以更改分割器的渲染方式,例如更改手柄的背景颜色。
您可以在 https://doc.qt.io 找到有关 Qt 样式表的更多信息/qt-5/stylesheet-reference.html
This is true for every splitter at least with WinXP and the default Luna thema (changing to classic solves the problem).
If you want to stay with Luna you may change the way the splitters are rendered, e.g. by changing the background color of the handle.
You may find more on Qt style sheets at https://doc.qt.io/qt-5/stylesheet-reference.html
您可以子类化 QSplitter 并覆盖它的受保护的虚拟 QSplitterHandle * QSplitter::createHandle() 来返回任何让您满意的内容。
例如,从该重载方法中,您可以使用自定义绘图返回
QSplitterHandle
的子类。You can subclass QSplitter and override it's
protected virtual QSplitterHandle * QSplitter::createHandle()
to return anything that makes you happy.For example, from that overloaded method you can return subclass of
QSplitterHandle
with custom drawing.感谢梅鲁拉的回答...我尝试了这个,现在我的分离器是可见的,看起来非常漂亮,但看起来并不突兀。此代码适用于使用 PyQt 或 PySide 的 Python。
Thanks to Merula's answer... I tried this and now my splitters are visible and look very nice without looking obtrusive. This code is for Python using PyQt or PySide.
使用要添加句柄的 QSplitter 调用 splitter_handles {}:
结果:
splitter_handles.h
main.c
Call splitter_handles {} with the QSplitter you want to add handles to:
Result:
splitter_handles.h
main.c