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. Set tab alignment for QTabBar whith is not within QTabWidget
Forum Updated to NodeBB v4.3 + New Features

Set tab alignment for QTabBar whith is not within QTabWidget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 383 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.
  • Y Offline
    Y Offline
    YuJin
    wrote on last edited by
    #1

    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.
    a8ccf722-d150-4432-a070-41a774bf7ac0-图片.png

    Note:
    1 Is the result wihtin QTabWidget.
    2 Is the result not within QTabWidget.

    Axel SpoerlA 1 Reply Last reply
    0
    • Y YuJin

      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.
      a8ccf722-d150-4432-a070-41a774bf7ac0-图片.png

      Note:
      1 Is the result wihtin QTabWidget.
      2 Is the result not within QTabWidget.

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by Axel Spoerl
      #2

      @YuJin
      I struggle to see, how the calls to setStyleSheet()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 from QTabBar and adds some specific implementations. I assume, that the first code snippet is located in a class inheriting from QMainWindow. You can find and customize those tab bars, by adding

      const auto bars = findChildren<QTabBar *>();
      for (auto *bar : bars)
          bar->setLayoutDirection(Qt::RightToLeft);
      

      Software Engineer
      The Qt Company, Oslo

      Y 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        @YuJin
        I struggle to see, how the calls to setStyleSheet()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 from QTabBar and adds some specific implementations. I assume, that the first code snippet is located in a class inheriting from QMainWindow. You can find and customize those tab bars, by adding

        const auto bars = findChildren<QTabBar *>();
        for (auto *bar : bars)
            bar->setLayoutDirection(Qt::RightToLeft);
        
        Y Offline
        Y Offline
        YuJin
        wrote on last edited by
        #3

        @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.
        190ba183-ef05-49da-9acb-b1127ec75248-图片.png

        Think you very much!
        The function setLayoutDircetion works in windows.

        cd1a18d3-23e8-4d4a-b04a-d29536d8e1e1-图片.png

        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 SpoerlA 1 Reply Last reply
        0
        • Y YuJin has marked this topic as solved on
        • Y YuJin

          @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.
          190ba183-ef05-49da-9acb-b1127ec75248-图片.png

          Think you very much!
          The function setLayoutDircetion works in windows.

          cd1a18d3-23e8-4d4a-b04a-d29536d8e1e1-图片.png

          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 SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          @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.

          Software Engineer
          The Qt Company, Oslo

          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