• QT 利用QSplitter 分割区域, 并添加QScrollArea 滚动区域,滚动条


    1. QSplitter 分割区域, 可以分割区域中可以随意添加自己的布局

    2.

    #include "dialog.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        //Dialog w;
        //w.show();
    
        QTextEdit *editor1 = new QTextEdit("test1");
        QTextEdit *editor2 = new QTextEdit("test2");
        QTextEdit *editor3 = new QTextEdit("test3");
    
        QSplitter *splitter = new QSplitter(Qt::Vertical);
        splitter->addWidget(editor1);
        splitter->addWidget(editor2);
    
        QSplitter mainsp(Qt::Horizontal);
        mainsp.addWidget(editor3);
        mainsp.addWidget(splitter);
    
        mainsp.show();
        
        return a.exec();
    }
    


    3.  添加滚动条

    #include "dialog.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        //Dialog w;
        //w.show();
    
        QTextEdit *editor1 = new QTextEdit("test1");
        QTextEdit *editor2 = new QTextEdit("test2");
        QTextEdit *editor3 = new QTextEdit("test3");
    
        QSplitter *splitter = new QSplitter(Qt::Vertical);
        splitter->addWidget(editor1);
        splitter->addWidget(editor2);
    
        QSplitter *mainsp = new QSplitter(Qt::Horizontal);
        mainsp->addWidget(editor3);
        mainsp->addWidget(splitter);
    
        QScrollArea scrollArea;
        scrollArea.setWidget(mainsp);
        scrollArea.viewport()->setBackgroundRole(QPalette::Dark);
        scrollArea.viewport()->setAutoFillBackground(true);
        scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);  //控件大小 小于 视窗大小时,默认不会显示滚动条
        scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);    //强制显示滚动条。
        scrollArea.show();
        
        return a.exec();
    }
    


     

  • 相关阅读:
    1619: 【例 1】Prime Distance
    Apache的架构师们遵循的30条设计原则(转帖)
    DP秒思维
    dsu on tree入门
    莫队入门
    行列式与霍尔基夫矩阵
    高精度板子
    splay入门
    回文自动机入门
    AC自动机
  • 原文地址:https://www.cnblogs.com/xj626852095/p/3648223.html
Copyright © 2020-2023  润新知