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. Text of styled font is clipped
Forum Updated to NodeBB v4.3 + New Features

Text of styled font is clipped

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 1.4k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by
    #1

    Hi,

    I'm playing with styling a QTabWidget according this blog

    and when I use font: bold; for selected texts, the text will be cut on both sides. Looks like tab does not use fontMetrics of styled font.
    I tried different settings for padding and margin, but was not able to get clean text display.

    TextCut03.jpg

    I looked at docs of QTabBar - there's no special functions for font settings - just setFont from QWidget.

    Is there a way to set font of selected tab directly without using stylesheet?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Known problem: https://bugreports.qt.io/issues/?jql=text ~ "QTabBar text"

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • D Offline
        D Offline
        django.Reinhard
        wrote on last edited by
        #3

        Whow! Know issue for about 5 years.
        Guess this issue will never be fixed.

        So I started to research for extending QTabWidget, but then I thought of something much simpler, almost ingenious. I wanted bigger padding around tab-text anyway, so I changed the function, that adds pages to the notebook to wrap the tab text with spaces.

        Now I have clean visual impression :)

        D 1 Reply Last reply
        0
        • D django.Reinhard

          Whow! Know issue for about 5 years.
          Guess this issue will never be fixed.

          So I started to research for extending QTabWidget, but then I thought of something much simpler, almost ingenious. I wanted bigger padding around tab-text anyway, so I changed the function, that adds pages to the notebook to wrap the tab text with spaces.

          Now I have clean visual impression :)

          D Offline
          D Offline
          Dariusz
          wrote on last edited by
          #4

          @django-Reinhard can you post fix? I'm hitting it too...

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AhmedAlshawi
            wrote on last edited by
            #5

            I have come across a similar issue but affecting the text on the bottom (see the p's and g's), and I can't seem to solve. Anyone have any idea?

            fa5776f4-376e-4d12-ad17-fd041f156e5e-image.png

            I resolved the problem of text being clipped at the sides by adding spaces in at either end of the tab names. Not ideal but does the job.
            e.g. " Clipping " instead of "Clipping"

            D 1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #6

              the cleaner solution would be to intercept the size of the tab via a proxy style (but wont probably not work with a stylesheet style) or subclassing QTabBar and reimplement initStyleOption() (virtual since Qt6 only)
              https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qtabbar.cpp?h=5.15.2#n245

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • A AhmedAlshawi

                I have come across a similar issue but affecting the text on the bottom (see the p's and g's), and I can't seem to solve. Anyone have any idea?

                fa5776f4-376e-4d12-ad17-fd041f156e5e-image.png

                I resolved the problem of text being clipped at the sides by adding spaces in at either end of the tab names. Not ideal but does the job.
                e.g. " Clipping " instead of "Clipping"

                D Offline
                D Offline
                django.Reinhard
                wrote on last edited by
                #7

                @AhmedAlshawi said in Text of styled font is clipped:

                I have come across a similar issue but affecting the text on the bottom (see the p's and g's), and I can't seem to solve. Anyone have any idea?

                Don't change fontsize by stylesheet.
                Instead use QWidget::setFont() like this:

                  tw = new QTabWidget();
                  tw->setFont(QFont(tw->font().family(), 16));
                

                looks like:
                QTabButtonFont03.jpg
                You see - no vertical clipping :)
                I don't use stylesheets for font-changes at all.
                QTabBar was the first widget, I had to :(

                @raven-worx said in Text of styled font is clipped:

                he cleaner solution would be to intercept the size of the tab via a proxy style (but wont probably not work with a stylesheet style) or subclassing QTabBar and reimplement initStyleOption() (virtual since Qt6 only)

                Well, that may be true.
                When I digged into the sources, I thought I'd start to extend QSize QTabBar::tabSizeHint(int index) const
                ...

                ... but I decided not to spend too much time into patching Qt.
                Especially as the workaround costs nothing and works like charming :)

                1 Reply Last reply
                0

                • Login

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