Skip to content

Commit

Permalink
Add support for right-to-left layout in FancyTabWidget
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Feb 21, 2024
1 parent f1804b9 commit 5feb492
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/QtFancyTabWidget/fancytabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QStyleOptionTabBarBase>
#include <QStylePainter>
#include <QLineEdit>
#include <QApplication>

#include <QDebug>

Expand Down Expand Up @@ -77,7 +78,13 @@ FancyTabWidget::FancyTabWidget(QWidget *parent)

connect(tabBar(), &QTabBar::tabBarDoubleClicked, this, &FancyTabWidget::onTabBarDoubleClick);

setCornerWidget(addButton);
if(qApp->isLeftToRight()) {
setCornerWidget(addButton,Qt::TopRightCorner);
setCornerWidget(nullptr,Qt::TopLeftCorner);
} else {
setCornerWidget(addButton,Qt::TopLeftCorner);
setCornerWidget(nullptr,Qt::TopRightCorner);
}

setFocusPolicy(Qt::StrongFocus);
}
Expand Down Expand Up @@ -183,5 +190,12 @@ void FancyTabWidget::adjustTabLineEdit()

void FancyTabWidget::retranslateUi(void)
{
if(qApp->isLeftToRight()) {
setCornerWidget(addButton,Qt::TopRightCorner);
setCornerWidget(nullptr,Qt::TopLeftCorner);
} else {
setCornerWidget(addButton,Qt::TopLeftCorner);
setCornerWidget(nullptr,Qt::TopRightCorner);
}
addButton->retranslateUi();
}

0 comments on commit 5feb492

Please sign in to comment.