对齐 qTableWidget 中的可勾选项 [英] Align checkable items in qTableWidget

查看:55
本文介绍了对齐 qTableWidget 中的可勾选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 tableWidget 中,我有一列完全由可检查项目组成.我不知道如何将复选框居中或至少删除它旁边的文本框.正如你在这张图片上看到的 当我点击单元格时,文本框有那个丑陋的轮廓,如果可能的话,我希望在整个表中关闭.我读过我需要使用委托来控制项目/图标的定位,但对于像我这样的菜鸟来说,理解这一点需要很长时间,所以如果有一些简单的解决方案可以使该列不那么难看,请提供示例,我们将不胜感激.

In tableWidget I have one column entirely made up of checkable items. I can't figure out how to center the checkbox or at least remove the text-box next to it. As you can see on this picture text-box has that ugly outline when I click on cell, I would like that turned off in entire table if it's possible. I've read that I need to use a delegates to control the positioning of items/icons, but for nooby like me it would take too long to understand that right, so if there is some simple solution that will make that column less ugly, please, examples would be appreciated.

推荐答案

那个矩形是一个焦点调整和 不能通过样式表隐藏.

That rectangle is a focus recangle and cannot be hidden via an stylesheet.

所以你有四个选项:

1 - 看来你可以使用

1 - It seems that u can use

 tablewidget->setFocusPolicy(Qt::NoFocus);

但是您将失去处理键盘事件的能力.请参阅FocusPolicy

But you will lose the ability to process keyboard events. See FocusPolicy

2 - 将可检查小部件设置为禁用,不能通过 setFlags 选择.我不知道这是否是一个错误,但在我的 Qt 中,我仍然可以点击复选框

2 - Set the checkable widgetitems as disabled, not selectable through setFlags. I don't know if this is a bug, but in my Qt i will be alowed to still click on checkboxes

3 - 通过 setFlags 也是,只是不要使用第二列.复选框将显示在与字符串相同的列中,但位于左侧.

3 - Set your first column as checkable though setFlags too, and just dont use that second column. Checkboxes will be shown in same column that the Strings but at left.

4- 您不想创建的自定义委托.

4- That custom delegate you dont want to create.

这里有一个例子

这篇关于对齐 qTableWidget 中的可勾选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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