Set tab alignment for QTabBar whith is not within QTabWidget
-
I create two dockwidget in mainwindow,and dock them in same dockarea.
QDockWidget* pDock1 = new QDockWidget("Console", this); QDockWidget* pDock2 = new QDockWidget("Project", this); addDockWidget(Qt::BottomDockWidgetArea, pDock1); addDockWidget(Qt::BottomDockWidgetArea, pDock2); tabifyDockWidget(pDock2, pDock1); setTabPosition(Qt::BottomDockWidgetArea, QTabWidget::North);
Also I create a QTabWidget as central widget for mainwindow. Add two widget to tabwidget.
QTabWidget* pMainWidget = new QTabWidget(this); pMainWidget->setObjectName("TabWidget"); setCentralWidget(pMainWidget); pMainWidget->addTab(new QWidget(this), "Game"); pMainWidget->addTab(new QWidget(this), "Scene");
I want both tabbar can draw tab from right to left.
I want use setStyleSheet to do this.
setStyleSheet("QTabBar::tab {subcontrol-position:right center;background:red}")
It don't work for layout positioni,but background color wroks!
Then I replace styleSheet with
setStyleSheet("QTabWidget::tab-bar {subcontrol-position:right center;background:red}");
After that position works on QTabBar within QTabWidget.
How can I set Tab alignment for QTabBar not within QTabWidget.
Result of the code.
Note:
1 Is the result wihtin QTabWidget.
2 Is the result not within QTabWidget. -
I create two dockwidget in mainwindow,and dock them in same dockarea.
QDockWidget* pDock1 = new QDockWidget("Console", this); QDockWidget* pDock2 = new QDockWidget("Project", this); addDockWidget(Qt::BottomDockWidgetArea, pDock1); addDockWidget(Qt::BottomDockWidgetArea, pDock2); tabifyDockWidget(pDock2, pDock1); setTabPosition(Qt::BottomDockWidgetArea, QTabWidget::North);
Also I create a QTabWidget as central widget for mainwindow. Add two widget to tabwidget.
QTabWidget* pMainWidget = new QTabWidget(this); pMainWidget->setObjectName("TabWidget"); setCentralWidget(pMainWidget); pMainWidget->addTab(new QWidget(this), "Game"); pMainWidget->addTab(new QWidget(this), "Scene");
I want both tabbar can draw tab from right to left.
I want use setStyleSheet to do this.
setStyleSheet("QTabBar::tab {subcontrol-position:right center;background:red}")
It don't work for layout positioni,but background color wroks!
Then I replace styleSheet with
setStyleSheet("QTabWidget::tab-bar {subcontrol-position:right center;background:red}");
After that position works on QTabBar within QTabWidget.
How can I set Tab alignment for QTabBar not within QTabWidget.
Result of the code.
Note:
1 Is the result wihtin QTabWidget.
2 Is the result not within QTabWidget.@YuJin
I struggle to see, how the calls tosetStyleSheet()
actually affect the picture shown: They are supposed to make the tabs have a red background, while the picture shows a grey background.To set a right-to-left layout direction, you can simply call
setLayoutDirection(Qt::RightToLeft)
on any widget. The tab bar used for dock widgets (both in a floating tab and on the main window) inherits fromQTabBar
and adds some specific implementations. I assume, that the first code snippet is located in a class inheriting fromQMainWindow
. You can find and customize those tab bars, by addingconst auto bars = findChildren<QTabBar *>(); for (auto *bar : bars) bar->setLayoutDirection(Qt::RightToLeft);
-
@YuJin
I struggle to see, how the calls tosetStyleSheet()
actually affect the picture shown: They are supposed to make the tabs have a red background, while the picture shows a grey background.To set a right-to-left layout direction, you can simply call
setLayoutDirection(Qt::RightToLeft)
on any widget. The tab bar used for dock widgets (both in a floating tab and on the main window) inherits fromQTabBar
and adds some specific implementations. I assume, that the first code snippet is located in a class inheriting fromQMainWindow
. You can find and customize those tab bars, by addingconst auto bars = findChildren<QTabBar *>(); for (auto *bar : bars) bar->setLayoutDirection(Qt::RightToLeft);
@Axel-Spoerl
Sorry about that.
The picture is the second sytlesheet result.setStyleSheet("QTabWidget::tab-bar {subcontrol-position:right center;background:red}");
Only QTabwidget tab position affected.
The first stylesheet affect for background like this.
Think you very much!
The function setLayoutDircetion works in windows.I try it before. But I don't remeber wther it works in maxOS.
I will try it later.By the way,Is there any way to control QTabBar layout direction by Qss which is not whitin QTabWidget?
-
-
@Axel-Spoerl
Sorry about that.
The picture is the second sytlesheet result.setStyleSheet("QTabWidget::tab-bar {subcontrol-position:right center;background:red}");
Only QTabwidget tab position affected.
The first stylesheet affect for background like this.
Think you very much!
The function setLayoutDircetion works in windows.I try it before. But I don't remeber wther it works in maxOS.
I will try it later.By the way,Is there any way to control QTabBar layout direction by Qss which is not whitin QTabWidget?
@YuJin said in Set tab alignment for QTabBar whith is not within QTabWidget:
By the way,Is there any way to control QTabBar layout direction by Qss which is not whitin QTabWidget?
No, as far as I know. That would not make too much sense, as this property is style-independent.