跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  2. Qt Development
  3. General and Desktop
  4. QGroupBox, QScrollArea, QFormLayout
Forum Updated to NodeBB v4.3 + New Features

QGroupBox, QScrollArea, QFormLayout

已排程 已置頂 已鎖定 已移動 Solved General and Desktop
41 貼文 7 Posters 7.3k 瀏覽 4 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • M mpergand

    Widget.h

    #include <QWidget>
    
    class QScrollArea;
    class QFormLayout;
    
    class Widget : public QWidget
        {
            Q_OBJECT
            
        public:
            
                    explicit Widget(QWidget *parent = nullptr);
                    
        private:
                          void  showEvent(QShowEvent* event);
                   QScrollArea* pScrollArea;
                   QFormLayout* pFormLayout;
    };
    

    Widget.cpp

    Widget::Widget(QWidget *parent) : QWidget(parent)
    {
        auto vLayout=new QVBoxLayout;
        setLayout(vLayout);
        
        pScrollArea=new QScrollArea;
        vLayout->addWidget(pScrollArea);
        
        auto sWidget=new QWidget;
        pScrollArea->setWidget(sWidget);
        pScrollArea->setWidgetResizable(true);
       
        pFormLayout=new QFormLayout;
        pFormLayout->setContentsMargins(0,0,0,1);
        pFormLayout->setSpacing(0);
        pFormLayout->setHorizontalSpacing(10);
        sWidget->setLayout(pFormLayout);
    
        // add one row for calculation in showEvent
        pFormLayout->addRow("", new QLabel());  
    
        vLayout->addWidget(new QPushButton("Clear"));
    }
    
    SPlattenS 離線
    SPlattenS 離線
    SPlatten
    寫於 最後由 編輯
    #41

    @mpergand , Thank you, works a treat...now to port to my main application:

        ui->setupUi(this);
    
        QVBoxLayout* pvbxLayout(new QVBoxLayout);
        mpsa = new QScrollArea;
        pvbxLayout->addWidget(mpsa);
    
        QWidget* pContainer(new QWidget);
        mpsa->setWidget(pContainer);
        int intFixedHeight(fontMetrics().height() * 3);
        mpsa->setFixedHeight(intFixedHeight);
        mpsa->setWidgetResizable(true);
    
        mpFormLayout = new QFormLayout;
        mpFormLayout->setContentsMargins(0,0,0,0);
        mpFormLayout->setSpacing(0);
        mpFormLayout->setHorizontalSpacing(10);
        pContainer->setLayout(mpFormLayout);
    
        for( int i=1; i<=10; i++ ) {
            mpFormLayout->addRow(QString::number(i),
                                 new QLabel(QString("Hello World: %1").arg(i)));
        }
        pvbxLayout->addWidget(new QPushButton("HELLO"));
        ui->centralwidget->setLayout(pvbxLayout);
    

    Kind Regards,
    Sy

    1 條回覆 最後回覆
    0

    • 登入

    • Login or register to search.
    • 第一個貼文
      最後的貼文
    0
    • 版面
    • 最新
    • 標籤
    • 熱門
    • 使用者
    • 群組
    • 搜尋
    • Get Qt Extensions
    • Unsolved