欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++?Qt實(shí)現(xiàn)動(dòng)態(tài)增加垂直滾動(dòng)條

 更新時(shí)間:2023年08月28日 09:38:44   作者:執(zhí)念斬長河  
本博文源于筆者正在工作的一個(gè)小內(nèi)容,內(nèi)容涉及到為qt動(dòng)態(tài)增加垂直滾動(dòng)條,文章分為三個(gè)部分,問題起源,問題解決方案,問題解決成功效果,思路清晰,文章干貨滿滿,復(fù)制源碼即可使用,需要的朋友可以參考下

問題起源

qt中一個(gè)頁面測試項(xiàng)一共很多種,如果都在一個(gè)頁面顯示就會(huì)顯得很臃腫,如果有個(gè)動(dòng)態(tài)創(chuàng)建時(shí)有個(gè)可以下拉的滾動(dòng)條就很好。下面讀者可以看下沒有滾動(dòng)條的頁面

問題解決方案

#include "widget.h"
#include <QApplication>
#include <QtGui>
#include <QVBoxLayout>
#include <QTableWidget>
#include <QPushButton>
#include <QLabel>
#include <QScrollArea>
#include<QGroupBox>
#include<QCheckBox>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget *page = new QWidget; //整個(gè)內(nèi)容
    QVBoxLayout* mainLayout = new QVBoxLayout(page);//鋪滿整個(gè)頁面
    QScrollArea* scrollArea = new QScrollArea;
    QWidget* contentWidget = new QWidget;
    QVBoxLayout* contentLayout = new QVBoxLayout(contentWidget);//將layout綁定起來了
    scrollArea->setWidgetResizable(true);
    contentLayout->setAlignment(Qt::AlignTop);
    QTabWidget tabWidget;
    QWidget tab1,tab2;
    // 模擬數(shù)據(jù)
    QList<QString> caseNames;
       caseNames << "Case 1" << "Case 2" << "Case 3" << "Case 4" << "Case 5" << "Case 6" << "Case 7" << "Case 8";
       for (int i = 0; i < caseNames.size(); i++) {
           if (i % 2 == 0) { // 每兩個(gè)groupBox為一行
               QHBoxLayout* rowLayout = new QHBoxLayout();
               contentLayout->addLayout(rowLayout);
           }
           QGroupBox* groupBox = new QGroupBox(caseNames[i], &tab1);
           groupBox->setFixedSize(200, 50);
           QVBoxLayout* groupBoxLayout = new QVBoxLayout(groupBox);
           groupBox->setLayout(groupBoxLayout);
           QCheckBox* checkBox = new QCheckBox(("Enabled"), groupBox);
           checkBox->setChecked(true);
           groupBoxLayout->addWidget(checkBox);
           QHBoxLayout* rowLayout = dynamic_cast<QHBoxLayout*>(contentLayout->itemAt(contentLayout->count() - 1)->layout());
           rowLayout->addWidget(groupBox);
       }
       scrollArea->setWidget(contentWidget); // 將內(nèi)容窗口設(shè)置為滾動(dòng)區(qū)域的子控件
       mainLayout->addWidget(&tabWidget);
       mainLayout->addWidget(scrollArea); // 將滾動(dòng)區(qū)域添加到主布局中
    page->setLayout(mainLayout);
    page->show();
    return a.exec();
}

問題解決效果

到此這篇關(guān)于C++ Qt實(shí)現(xiàn)動(dòng)態(tài)增加垂直滾動(dòng)條的文章就介紹到這了,更多相關(guān)C++ Qt動(dòng)態(tài)增加垂直滾動(dòng)條內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論