简体   繁体   中英

Customize appearance QTabWidget

I am currently working on Qt application. There I am using QTabWidget with several tabs.

QTabWidget is embedded into QVBoxLayout. My question is that tabs added appear centered and I would like them to be left aligned. How could I achieve that?

在此处输入图片说明

I would like to change appearance as well. Is the only way to override the paintEvent of QTabBar?

I am using Qt and C++, no QML

Thanks and regards

You should try styling the tab widget with a style sheet, this way:

QString ss = "QTabWidget::tab-bar { alignment: left; }";
ui->tabWidget->setStyleSheet(ss);

The style sheet can be set using the designer, though. Just right click the widget and choose Change stylesheet ... from the pop up menu, then insert the style in the dialog and click the Ok button when done, or the Apply button to check the effect before closing the dialog box.

You can find the official documentation here and here .

You can refer to this post to see how to style the tab widget further.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM