Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTabWidget:: How to remove the blank area of QTabWidget



  • TabBar is hidden in the custom TabWidget, and then there are some margins that I cannot hide
    alt text
    Try setContentsMargins(0, 0, 0, 0) Does not work

    Example:

    
    #include <QApplication>
    #include <QMainWindow>
    #include <QWidget>
    #include <QHBoxLayout>
    #include <QTabBar>
    #include <QTabWidget>
    
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
    
        QMainWindow mainWindow;
        mainWindow.resize(900, 900);
    
        QWidget *contentWidget = new QWidget(&mainWindow);
        QTabWidget *tabWidget = new QTabWidget(contentWidget);
    
        QWidget *myWidget = new QWidget;
    
        QPalette palette = myWidget->palette();
        myWidget->setAutoFillBackground(true);
        palette.setColor(QPalette::Window, QColor(255, 0, 255));
        myWidget->setPalette(palette);
        tabWidget->addTab(myWidget, "test");
        tabWidget->setTabPosition(QTabWidget::West);
        tabWidget->setContentsMargins(0, 0, 0, 0);
    
        tabWidget->tabBar()->setExpanding(false);
        tabWidget->tabBar()->hide();
    
        QHBoxLayout layout;
        layout.setMargin(0);
        layout.setSpacing(0);
        layout.setContentsMargins(0, 0, 0, 0);
        layout.addWidget(tabWidget, 1);
    
        contentWidget->setLayout(&layout);
        contentWidget->show();
    
        mainWindow.setCentralWidget(contentWidget);
        mainWindow.show();
    
        return app.exec();
    }
    

    I searched for answers in many places, but I did not find the desired result.


  • Qt Champions 2019

    @PengPeng said in QTabWidget:: How to remove the blank area of QTabWidget:

    tabWidget

    I think you need to set content margins on mainWindow.layout()



  • @jsulm
    Try

    mainWindow.layout()->setMargin(0);
    mainWindow.layout()->setSpacing(0);
    mainWindow.layout()->setContentsMargins(0, 0, 0, 0);
    

    This doesn't seem to work


  • Lifetime Qt Champion

    Hi
    I think it comes from the tabWidget itself.
    alt text


  • Lifetime Qt Champion

    Hi
    Try with
    tabWidget->setStyleSheet( "QTabWidget::pane { border: 0px;}" );
    for me on windows that makes it go to border.

    before
    alt text

    after
    alt text



  • @mrjj This works for me, awesome 👍


Log in to reply