Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Translated title of QGroupBox larger in width than QGroupbox
Qt 6.11 is out! See what's new in the release blog

Translated title of QGroupBox larger in width than QGroupbox

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 830 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HappyCoder
    wrote on last edited by
    #1

    Hi,
    we have a software for our customers and now we got back the first
    translations from our company representation outside of Germany.
    The german and english title of the group box looks nice but the
    spanish title is very long. Currently the title is not completely visible,
    some characters on the right side are missing.

    The groupbox is in a QTabWidget with a vertical layout.
    The title of each groupbox is set to bold using stylesheets.
    The normal text with the groupbox is not bold.

    I tried to calc the width using QFontMetrics, but however, the calculated size was
    smaler the the current width of the groupbox, what makes no sence.

    How can i achieve that the groupbox resize that the full bold title is visible?
    Thx

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      I think you might have spotted a bug. the problem looks like is in QGroupBox::minimumSizeHint() try subclassing QGroupBox and reimplementing virtual QSize QGroupBox::minimumSizeHint() const override

      QSize QGroupBox::minimumSizeHint() const
      {
      QStyleOptionGroupBox option;
              initStyleOption(&option);
      
               //QFontMetrics metrics(fontMetrics());  // Wrong
               QFontMetrics metrics(option.fontMetrics); //Right
      
              int baseWidth = metrics.width(title()) + metrics.width(QLatin1Char(' '));
              int baseHeight = metrics.height();
              if (isCheckable()) {
                  baseWidth += style()->pixelMetric(QStyle::PM_IndicatorWidth);
                  baseWidth += style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing);
                  baseHeight = qMax(baseHeight, style()->pixelMetric(QStyle::PM_IndicatorHeight));
              }
      
              QSize size = style()->sizeFromContents(QStyle::CT_GroupBox, &option, QSize(baseWidth, baseHeight), this);
              return size.expandedTo(QWidget::minimumSizeHint());
          }
      

      (you probably could even use const QFontMetrics& metrics=option.fontMetrics; here or use option.fontMetrics directly where metrics is used) if this fixes your problem it might be worth opening a bug report so that it will be fixed in futre Qt versions

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved