设置QGroupBox标题的对齐方式 [英] Set alignment of QGroupBox title

查看:145
本文介绍了设置QGroupBox标题的对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以编程方式设置QGroupBox标题的对齐方式.根据

我在环境中遇到的这种行为:

  • Debian 9.0(sid);
  • Qt 5.5.1(从存储库安装);
  • XMonad DE.

与下一个环境相同的行为:

  • Ubuntu 15.10;
  • Qt 5.4(使用离线安装程序手动安装);
  • KDE.

但是!如果我使用从存储库(Qt 5.4.2)安装的Qt,则标题默认情况下将与中心对齐.但是,如果我将align更改为左侧,则不会更改.

我尝试通过Google找到一些解决方案,但是我没有找到类似的问题,这是一个不好的信号,通常这意味着我做错了一些事情.

所以我的问题是:为什么我不能通过对齐组框标题来进行管理.

解决方案

似乎在Qt 5.5.1中,当计算标题的rect时未考虑QGroupBox标题对齐时,某些视觉样式存在错误:href ="https://bugreports.qt.io/browse/QTBUG-49068" rel ="nofollow"> QTBUG-49068:QGroupBox标题不遵循融合样式的对齐方式.

您可以从git存储库下载最新版本,进行构建,然后检查是否已修复该错误(已针对Fusion风格: bugtracker .

I try programmatically set alignment of title of QGroupBox. According to the documentation I try to do it in the following way:

MainWidget::MainWidget (QWidget * parent)
            : QWidget (parent)
{
    setWindowTitle (tr ("QGropBox Title Alignment issue") );

    QGroupBox * group = new QGroupBox ("Group Title", this);
    QVBoxLayout * layoutTop = new QVBoxLayout ();
    layoutTop->addWidget (group);
    group->setAlignment (Qt::AlignHCenter);
    this->setLayout (layoutTop);
}

But I have got unexpected result and title aligned with the left-hand side of the group box.

Such behaviour I have got with the environment:

  • Debian 9.0 (sid);
  • Qt 5.5.1 (installed from repository);
  • XMonad DE.

The same behaviour I have got with the next environment:

  • Ubuntu 15.10;
  • Qt 5.4 (installed manually using offline-installer);
  • KDE.

But! If I use Qt installed from repository (Qt 5.4.2) the title will aligned with the centre by default. But if I change align to the left it will not changed.

I try find some solution with Google, but I haven't found similar questions and this is bad sign and usually this is means that I do some thing wrong.

So my question is: Why I can't manage by alignment of the group box title.

解决方案

It seems like in Qt 5.5.1 there is a bug for some visual styles when QGroupBox title alignment is not taken into account when title's rect is computed: QTBUG-49068: QGroupBox title does not follow alignment with fusion style.

You can download most recent version from git repository, build it and check if the bug has been fixed (is has been for Fusion style: qt commit 139953).

If bug still occurs, I think you should submit an issue to Qt bugtracker.

这篇关于设置QGroupBox标题的对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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