更改 QCheckBox 的复选框位置 [英] Change checkbox position for a QCheckBox

查看:124
本文介绍了更改 QCheckBox 的复选框位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格布局中有一个 QCheckbox,定义如下:

I have a QCheckbox in a grid layout defined as such:

self.isSubfactorCheckbox = QtGui.QCheckBox('Is &subfactor', self)

默认情况下,复选框位于是子因子"文本的左侧.我想把它移到文本的右边.

By default the checkbox is to the left of the "Is subfactor" text. I wish to move it to the right of the text.

我尝试过使用 subcontrol-position 但无济于事.

I've tried playing around with subcontrol-position but to no avail.

self.isSubfactorCheckbox.setStyleSheet('QCheckBox::indicator{subcontrol-origin: content; subcontrol-position: top right;}')

这会将复选框移到右侧(它仍然在文本的左侧),但会将文本推到右侧并移出窗口边缘.

This moves the checkbox to the right (it's still on the left of the text) but it pushes the text to the right and out of the window's edge.

这无助于将文本向右移动:

This didn't help to move the text to the right:

self.isSubfactorCheckbox.setStyleSheet('QCheckBox::text{subcontrol-origin: content; subcontrol-position: top left; }')

一个解决方案是创建一个 QLabel 并在其右侧添加复选框,但我还没有找到在 QLabel 中给字母下划线的方法,以便用户知道哪个是快捷键.我试过用 & 前缀字母或将它们包装在 标签.

A solution would be creating a QLabel and adding the checkbox on its right but I don't haven't found a way to underline letters in a QLabel so that the user will know which is the shortcut key. I've tried prefixing letters with & or wrapping them in <u> </u> tags.

我仍然更喜欢只使用 QLabel,但是如何将复选框切换到文本右侧,而不会将文本推出.

I'd still prefer to use only a QLabel, but how would I switch the checkbox to the right of the text without the text getting pushed out.

推荐答案

使用伙伴机制.将 QCheckBox 设置为 QLabel 的好友.在那个前缀 & 之后将在标签中的快捷方式字符下划线.请参阅 QLabel 的 setBuddy 的文档.

Use the buddy mechanism. Set the QCheckBox to the buddy of the QLabel. After that prefix & will underline the shortcut character in the label. See the documentation of the QLabel's setBuddy.

这篇关于更改 QCheckBox 的复选框位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆