Fixed Tab Title Alignment

This commit is contained in:
ShaopengLin 2024-08-07 14:35:44 -04:00
parent 585d29d2aa
commit df6560c1a3
2 changed files with 18 additions and 2 deletions

View File

@ -176,15 +176,17 @@ QTabWidget::pane {
border-top: 1px solid #ccc;
}
/* paintEvent of src/tabbar.cpp references the value of border and padding */
QTabBar::tab {
border: 1px solid #ccc;
border-radius: 0;
padding: 2px;
padding: 4px;
padding-top: 6px;
}
QTabBar::tab:selected {
background-color: white;
border-bottom: 2px solid white;
border-bottom: 1px solid white;
}
QTabBar::tab:first {

View File

@ -425,8 +425,22 @@ void TabBar::paintEvent(QPaintEvent *e)
bool textRightToLeft = tab_title.isRightToLeft();
bool appRightToLeft = QWidget::isRightToLeft();
// See QTabBar::tab::padding value in resources/css/style.css
const int padding = 4;
QRect tabTextRect = style()->subElementRect(QStyle::SE_TabBarTabText, &tabopt, this);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// See QTabBar::tab::border value in resources/css/style.css
const int border = 1;
// Add Padding to left, right. Padding is 4px. Add 5 to account for
// Extra pixel from border.
tabTextRect.setX(tabTextRect.x() + padding + border);
tabTextRect.setWidth(tabTextRect.width() - padding - border);
#else
// Qt6 correctly adds left and right padding but now incorrectly adds
// top or bottom padding.
tabTextRect.setY(tabTextRect.y() - padding);
#endif
QRect fontTextRect = fontMetrics().boundingRect(tab_title);
if (fontTextRect.width() > tabTextRect.width())