Вопрос

image

Using a stylesheet I manage to set the background for the title element as shown in the image above (1.) using:

QGroupBox::title
{
    background-color: rgb(255, 255, 0);
    subcontrol-origin: margin;
    subcontrol-position: bottom center;
}

Now I want the title to expand to the maximum size of the hosting QGroupBox as shown in image 2.. How do I accomplish this?

Thanks!

Edit: I wish to do this using style sheets only.

Это было полезно?

Решение

It turns out my efforts to find a solution on Google failed due to incorrect search terms...

http://www.qtcentre.org/threads/43232-customizing-QGroupbox-title purposed setting

QGroupBox::title
{
  padding-left: 2000px;
  padding-right: 2000px;
}

Not very pretty but at least It could be done using stylesheets only.

Другие советы

You can set background-image to expand the title.

enter image description here

QGroupBox {
    border: 1px solid #90c6dd;
    border-radius: 0px;
    margin: 8px 8px 7px 7px;
    padding: 56px 10px 10px 10px;
    background-image: url(:/res/svg/group-bg.svg);
    background-repeat: repeat-x;
    background-position: top left;
}

QGroupBox::title {
    font-size: 24px;
    font-weight: bold;
    subcontrol-origin: padding;
    subcontrol-position: top left;
    min-height: 39px;
    padding: 0 10px 0 10px;
}

if you can get pointer on the QGroupBox parent you can get its width and knowing its parameter do the following:

this->setWidth(pOnParent->width());
padding-left: 100%;
padding-right: 100%;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top