Qt-TabWidget控件使用方法

 

相关资料:

https://blog.csdn.net/qq_31073871/article/details/79943093       QSS使用方法

https://blog.csdn.net/wzs250969969/article/details/78499428     样式一

https://download.csdn.net/download/zhujianqiangqq/13102879    代码包下载

 

.pro

 1 QT       += core gui
 2 
 3 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 4 
 5 CONFIG += c++11
 6 
 7 # The following define makes your compiler emit warnings if you use
 8 # any Qt feature that has been marked deprecated (the exact warnings
 9 # depend on your compiler). Please consult the documentation of the
10 # deprecated API in order to know how to port your code away from it.
11 DEFINES += QT_DEPRECATED_WARNINGS
12 
13 # You can also make your code fail to compile if it uses deprecated APIs.
14 # In order to do so, uncomment the following line.
15 # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
17 
18 SOURCES += \
19     main.cpp \
20     mainwindow.cpp
21 
22 HEADERS += \
23     mainwindow.h
24 
25 FORMS += \
26     mainwindow.ui
27 
28 # Default rules for deployment.
29 qnx: target.path = /tmp/$${TARGET}/bin
30 else: unix:!android: target.path = /opt/$${TARGET}/bin
31 !isEmpty(target.path): INSTALLS += target
32 
33 RESOURCES += \
34     TabWidget.qrc
View Code

main.cpp

 1 #include "mainwindow.h"
 2 
 3 #include <QApplication>
 4 #include <QFile>
 5 
 6 int main(int argc, char *argv[])
 7 {
 8     QApplication a(argc, argv);
 9 
10     QFile qss(":/new/QSS/tabWidget.qss");
11     if( qss.open(QFile::ReadOnly))
12     {
13         qDebug("open success");
14         QString style = QLatin1String(qss.readAll());
15         a.setStyleSheet(style);
16         qss.close();
17     }
18     else
19     {
20         qDebug("Open failed");
21     }
22 
23     MainWindow w;
24     w.show();
25     return a.exec();
26 }
View Code

mainWindow.h

 1 #ifndef MAINWINDOW_H
 2 #define MAINWINDOW_H
 3 
 4 #include <QMainWindow>
 5 #include <QTabWidget>
 6 #include <QLineEdit>
 7 
 8 QT_BEGIN_NAMESPACE
 9 namespace Ui { class MainWindow; }
10 QT_END_NAMESPACE
11 
12 class MainWindow : public QMainWindow
13 {
14     Q_OBJECT
15 
16 public:
17     MainWindow(QWidget *parent = nullptr);
18     ~MainWindow();
19 
20 private:
21     Ui::MainWindow *ui;
22 
23     QTabWidget *m_pTabWidget;
24 };
25 #endif // MAINWINDOW_H
View Code

mainWidow.cpp

 1 #include "mainwindow.h"
 2 #include "ui_mainwindow.h"
 3 
 4 MainWindow::MainWindow(QWidget *parent)
 5     : QMainWindow(parent)
 6     , ui(new Ui::MainWindow)
 7 {
 8     ui->setupUi(this);
 9 
10     m_pTabWidget = new QTabWidget(this);
11     m_pTabWidget->setStyleSheet("QTabWidget:pane {border:1px solid #e8f3f9; clolr:white; background:transparent;}");
12     m_pTabWidget->setTabShape(QTabWidget::Triangular);//设置选项卡的形状 Rounded
13     m_pTabWidget->setGeometry(20, 10, 400, 200);
14     m_pTabWidget->setTabPosition(QTabWidget::East);
15 
16     QWidget *tabCalibration = new QWidget(this);
17     QWidget *tabImage = new QWidget(this);
18     QWidget *tabEdit = new QWidget(this);
19 
20     m_pTabWidget->addTab(tabCalibration, QIcon(""), QStringLiteral("校准"));
21     QLineEdit *oEdit = new QLineEdit(tabCalibration);
22     oEdit->setGeometry(10, 10, 100, 30);
23 
24     m_pTabWidget->addTab(tabImage, QIcon(""), tr("image"));
25     QLineEdit *oEdit2 = new QLineEdit(tabImage);
26     oEdit2->setGeometry(10, 40, 100, 30);
27 
28     m_pTabWidget->addTab(tabEdit, QIcon(""), tr("edit"));
29     QLineEdit *oEdit3 = new QLineEdit(tabEdit);
30     oEdit3->setGeometry(10, 60, 100, 30);
31 }
32 
33 MainWindow::~MainWindow()
34 {
35     delete ui;
36 }
View Code

tabWidget.qss

 1 QTabWidget::pane { 
 2     border: 1px solid #FF0000;
 3     top: -0.1em;                //pane鐨刦rame鍚戜笂绉诲姩锛宐order-top涔熷悜涓婄Щ鍔�
 4 }
 5 QTabBar::tab {
 6         min-width: 18ex;
 7         padding: 8px;
 8 }
 9 QTabBar::tab:selected {
10     background: #F0F0F0;            //閫変腑鐨則ab鑳屾櫙棰滆壊瑕嗙洊pane鐨刦rame涓婇潰鐨刡order-top
11     border: 1px solid #FF0000;
12     border-bottom: none;
13     border-top-left-radius: 4px;
14         border-top-right-radius: 4px;
15 }
16 QTabBar::tab:!selected {
17     border-bottom: 1px solid #FF0000;
18 }
View Code

 

posted on 2020-11-10 19:43  疯狂delphi  阅读(1244)  评论(0编辑  收藏  举报

导航