QTabWidget:: How to remove the blank area of QTabWidget
Solved
General and Desktop
-
TabBar is hidden in the custom TabWidget, and then there are some margins that I cannot hide
TrysetContentsMargins(0, 0, 0, 0)
Does not workExample:
#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.
-
@PengPeng said in QTabWidget:: How to remove the blank area of QTabWidget:
tabWidget
I think you need to set content margins on mainWindow.layout()
-
Hi
I think it comes from the tabWidget itself.