Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. customizing QTabWidget
Forum Updated to NodeBB v4.3 + New Features

customizing QTabWidget

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 2.6k Views
  • 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.
  • M Offline
    M Offline
    mecctor
    wrote on 17 Nov 2021, 07:44 last edited by
    #1

    ![alt text](QQ截图20211117154205.png image url)
    when the tab was selected,how can I want to get rid of this bottom line?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AxelVienna
      wrote on 17 Nov 2021, 08:35 last edited by
      #2

      That depends on your stylesheet, which you typically load from a file and set it in main.cpp:

          // Read style sheet
          QFile file(":/yourStyleSheet.qss");
          file.open(QFile::ReadOnly | QFile::Text);
          QTextStream stream(&file);
          a.setStyleSheet(stream.readAll());
      

      As an example, a stylesheet without bottom lines on selected tabs is available here.

      C++ and Python walk into a bar. C++ reuses the first glass.

      M 1 Reply Last reply 17 Nov 2021, 08:46
      0
      • A AxelVienna
        17 Nov 2021, 08:35

        That depends on your stylesheet, which you typically load from a file and set it in main.cpp:

            // Read style sheet
            QFile file(":/yourStyleSheet.qss");
            file.open(QFile::ReadOnly | QFile::Text);
            QTextStream stream(&file);
            a.setStyleSheet(stream.readAll());
        

        As an example, a stylesheet without bottom lines on selected tabs is available here.

        M Offline
        M Offline
        mecctor
        wrote on 17 Nov 2021, 08:46 last edited by
        #3

        @AxelVienna thank u very much.
        here is my QSS

        QTabWidget::pane { /* The tab widget frame */
            border-top: 1px solid #C2C7CB;  /* here is the line*/
         padding:20px;
        }
        
        QTabWidget::tab-bar {
            left: 2px; /* move to the right by 5px */
        	
        }
        QTabWidget{
        	background-color:#ffffff;
        }
        /* Style the tab using the tab sub-control. Note that
            it reads QTabBar _not_ QTabWidget */
        QTabBar::tab {
        	/*margin:0px;/*0 这里可以让tab 跟 TabWidget连成一片*/
            margin-left:4px;
        	padding:4px;
        	border-top-left-radius: 6px;
            border-top-right-radius: 6px;
        	background:#ffffff;
        	border:1px solid #d9d9d9;
        	border-bottom:0px none;
        	min-height:20px;
        }
        
        QTabBar::tab:selected {
            border-color: #9B9B9B;
            border-bottom-color: #00ffff; /* same as pane color */
            margin-bottom:-1px;    /*here when selected,I want tab to lower a px. so to covery the line.
                                                       but the line is in front of tab*/
                                                 
        }
        
        1 Reply Last reply
        0
        • A Offline
          A Offline
          AxelVienna
          wrote on 17 Nov 2021, 08:57 last edited by
          #4

          You should disable the bottom like that:

          QTabBar::tab:bottom:selected:disabled, QDockWidget QTabBar::tab:bottom:selected:disabled {
            border-top: 3px solid #26486B;
            color: #9DA9B5;
            background-color: #455364;
          }
          
          

          C++ and Python walk into a bar. C++ reuses the first glass.

          M 1 Reply Last reply 17 Nov 2021, 09:10
          0
          • A AxelVienna
            17 Nov 2021, 08:57

            You should disable the bottom like that:

            QTabBar::tab:bottom:selected:disabled, QDockWidget QTabBar::tab:bottom:selected:disabled {
              border-top: 3px solid #26486B;
              color: #9DA9B5;
              background-color: #455364;
            }
            
            
            M Offline
            M Offline
            mecctor
            wrote on 17 Nov 2021, 09:10 last edited by mecctor
            #5

            @AxelVienna It do't work!
            03.jpg
            actualy above is i want to do.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AxelVienna
              wrote on 17 Nov 2021, 12:16 last edited by
              #6

              So what is your new code?

              C++ and Python walk into a bar. C++ reuses the first glass.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mecctor
                wrote on 17 Nov 2021, 12:42 last edited by
                #7
                This post is deleted!
                J 1 Reply Last reply 17 Nov 2021, 12:44
                0
                • M mecctor
                  17 Nov 2021, 12:42

                  This post is deleted!

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 17 Nov 2021, 12:44 last edited by jsulm
                  #8

                  @mecctor said in customizing QTabWidget:

                  the below is my QT QSS

                  The question was: how does your current code/style-sheet looks like? What you want to achieve is clear...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mecctor
                    wrote on 17 Nov 2021, 12:53 last edited by
                    #9
                    auto cutDir = QCoreApplication::applicationDirPath();
                    auto resFile = cutDir + "/TabWidget.css";
                    QFile cssFile(resFile);
                    if( cssFile.open(QFile::ReadOnly))
                    {
                        QString styleSheet = QLatin1String(cssFile.readAll());
                    
                        ui->tabWidget->setStyleSheet(styleSheet);
                        cssFile.close();
                    
                    }
                    
                    auto tab1 = new QTabBar;
                    auto tab2 = new QTabBar;
                    auto tab3= new QTabBar;
                    
                    /*tabLayout->addWidget(btn);
                    ui->tabWidget->setLayout(tabLayout);*/
                    

                    // tab1->setObjectName(QStringLiteral("TabName"));

                    ui->tabWidget->setTabsClosable(true);
                    
                    ui->tabWidget->addTab(tab1,QStringLiteral("网易中国"));
                    ui->tabWidget->addTab(tab2,QStringLiteral("百度"));
                    ui->tabWidget->addTab(tab3,QStringLiteral("爱奇艺"));
                    

                    and the file TabWidget.css is below:

                    QTabWidget::pane { /* The tab widget frame */
                    border-top: 1px solid #C2C7CB;
                    padding:20px;
                    }

                    QTabWidget::tab-bar {
                    left: 2px; /* move to the right by 5px */

                    }
                    QTabWidget{
                    background-color:#ffffff;
                    }
                    /* Style the tab using the tab sub-control. Note that
                    it reads QTabBar not QTabWidget */
                    QTabBar::tab {
                    /*margin:0px;/0 这里可以让tab 跟 TabWidget连成一片/
                    margin-left:4px;
                    padding:4px;
                    border-top-left-radius: 6px;
                    border-top-right-radius: 6px;
                    background:#ffffff;
                    border:1px solid #d9d9d9;
                    border-bottom:0px none;
                    min-height:20px;
                    }

                    QTabBar::tab:selected {
                    border-color: #9B9B9B;
                    border-bottom-color: #00ffff; /* same as pane color */
                    margin-bottom:-1px;
                    }

                    1 Reply Last reply
                    0

                    1/9

                    17 Nov 2021, 07:44

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved