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. QTabWidget TabBar font size weirdness
QtWS25 Last Chance

QTabWidget TabBar font size weirdness

Scheduled Pinned Locked Moved Solved General and Desktop
qtabwidgetqtabbarstylesheetfontsize
3 Posts 2 Posters 8.8k 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.
  • P Offline
    P Offline
    pauledd
    wrote on 11 Sept 2017, 05:57 last edited by
    #1

    Hi

    I currently struggle with the creation of an QTabWidget with customized QTabBar 's. I want the tabbars with black background, white text color, self-adjust in width (which I normally expected as standard behaviour...) and selected tabbar font size 12pt and the non-selected font size 22pt.

    I derived my main class from QTabWidget and created a simple
    MainWindow class. Then I applied three stylesheets to the tabbar to fulfil
    my desired look.
    The problem is each stylesheet seems to disable its previous stylesheet.
    In my code the last stylesheet that decreases the font size for the selected tab disables the the 22pt font for the unselected tab and the background colors. So if I run my code I get this window:

    0_1505108712071_Bildschirmfoto_2017-09-11_07-44-09.png

    As you can see, no colors were applied, the "GOD" tab is selected and has the desired 8pt font size, but the unselected seems to have the applications standart font size and not the huge 22pt I wanted.

    If I comment out the last two stylesheets I get my desired colors:

    0_1505108981084_Bildschirmfoto_2017-09-11_07-49-27.png

    If I comment out only the last stylesheet I get my desired unselected huge font size but color fails AND it doesnt scale the tabs width with the huge text.

    0_1505109167020_Bildschirmfoto_2017-09-11_07-50-31.png

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QTableWidget>
    
    class MainWindow : public QTabWidget
    {
        Q_OBJECT
    public:
        explicit MainWindow(QTabWidget *parent = 0);
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.cpp:

    #include "mainwindow.h"
    
    MainWindow::MainWindow(QTabWidget *parent)
        :QTabWidget(parent)
    {
        QWidget *tab1 = new QWidget;
        QWidget *tab2 = new QWidget;
    
        this->addTab(tab1,"GOD");
        this->addTab(tab2,"SATAN");
    
        this->tabBar()->setStyleSheet("QTabBar {background: #000000; color:#ffffff}");
        this->tabBar()->setStyleSheet("QTabBar::tab:!selected {font-size:22pt;}");
        this->tabBar()->setStyleSheet("QTabBar::tab:selected {font-size:8pt;}");
    
    }
    

    main.cpp

    #include <QApplication>
    #include "mainwindow.h"
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
        MainWindow mainWindow;
        mainWindow.show();
        return app.exec();
    }
    

    What am I doing wrong?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vinod Kuntoji
      wrote on 11 Sept 2017, 11:47 last edited by
      #2

      #pauledd,

      QString tabStyle = "QTabBar {background-color: #000000; color:#ffffff;}"
                         "QTabBar::tab:!selected {height: 50px; width: 100px;background-color: #000000; color:#ffffff;font-size:12pt;}"
                         "QTabBar::tab:selected {height: 50px; width: 100px;background-color: #000000; color:#ffffff;font-size:8pt;}";
      ui->tabWidget->setStyleSheet(tabStyle);
      

      C++, Qt, Qt Quick Developer,
      PthinkS, Bangalore

      1 Reply Last reply
      3
      • P Offline
        P Offline
        pauledd
        wrote on 11 Sept 2017, 14:55 last edited by
        #3

        Thank you! I see you specified height and width manually. That works so far. I will use that.

        1 Reply Last reply
        0

        1/3

        11 Sept 2017, 05:57

        • Login

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