Text of styled font is clipped
-
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.I looked at docs of QTabBar - there's no special functions for font settings - just
setFont
fromQWidget
.Is there a way to set font of selected tab directly without using stylesheet?
-
Known problem: https://bugreports.qt.io/issues/?jql=text ~ "QTabBar text"
-
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 :)
-
@django-Reinhard can you post fix? I'm hitting it too...
-
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?
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" -
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 -
@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 useQWidget::setFont()
like this:tw = new QTabWidget(); tw->setFont(QFont(tw->font().family(), 16));
looks like:
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 extendQSize 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 :)