zoukankan      html  css  js  c++  java
  • qtabwidget 垂直tab

    https://stackoverflow.com/questions/50578661/how-to-implement-vertical-tabs-in-qt#



    #include <QApplication>
    #include <QStyleOptionTab>
    #include <QStylePainter>
    #include <QTabBar>
    #include <QTabWidget>
    
    class TabBar: public QTabBar{
    public:
        QSize tabSizeHint(int index) const{
            QSize s = QTabBar::tabSizeHint(index);
            s.transpose();
            return s;
        }
    protected:
        void paintEvent(QPaintEvent * /*event*/){
            QStylePainter painter(this);
            QStyleOptionTab opt;
    
            for(int i = 0;i < count();i++)
            {
                initStyleOption(&opt,i);
                painter.drawControl(QStyle::CE_TabBarTabShape, opt);
                painter.save();
    
                QSize s = opt.rect.size();
                s.transpose();
                QRect r(QPoint(), s);
                r.moveCenter(opt.rect.center());
                opt.rect = r;
    
                QPoint c = tabRect(i).center();
                painter.translate(c);
                painter.rotate(90);
                painter.translate(-c);
                painter.drawControl(QStyle::CE_TabBarTabLabel,opt);
                painter.restore();
            }
        }
    };
    
    class TabWidget : public QTabWidget
    {
    public:
        TabWidget(QWidget *parent=0):QTabWidget(parent){
            setTabBar(new TabBar);
            setTabPosition(QTabWidget::West);
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        TabWidget w;
        w.addTab(new QWidget, "tab1");
        w.addTab(new QWidget, "tab2");
        w.addTab(new QWidget, "tab3");
        w.show();
    
        return a.exec();
    }
  • 相关阅读:
    jsp作业第二次
    软件测试课堂练习
    第七次作业
    第六次作业
    第五次作业
    第四次作业
    第七周作业
    jsp第六周作业
    jsp第四周作业
    jsp第二次作业
  • 原文地址:https://www.cnblogs.com/cute/p/15358185.html
Copyright © 2011-2022 走看看