Gluttton February 2016

Set alignment of QGroupBox title

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.

enter image description here

Such behaviour I have got with the environment:

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

enter image description here

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.

Answers


nnatarr February 2016

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.

Post Status

Asked in February 2016
Viewed 1,887 times
Voted 13
Answered 1 times

Search




Leave an answer