Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Resize of widget's array
Forum Updated to NodeBB v4.3 + New Features

Resize of widget's array

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 243 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mimamrafi
    wrote on 23 Aug 2022, 09:31 last edited by
    #1

    Hi everyone, I'm sorry about this newbie's question. I want to resize the widget's array, this is my latest codes

    //maingui.h
    #include "channelframe.h"
    ...
    private:
        Ui::MainGUI *ui;
        ChannelFrame *CF[8];
    
    //maingui.cpp
    MainGUI::MainGUI(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainGUI)
    {
        ui->setupUi(this);
    
        ui->tabWidget->widget(0)->setLayout(new QVBoxLayout);
        CF.resize (9);
        const uint array_size = sizeof(CF)/sizeof(CF[0]);
        for (uint i = 0; i < array_size; i++)
        {
            CF[i] = new ChannelFrame;
            connect(CF[i], &ChannelFrame::Next, this, &MainGUI::NextFocus);
            CF[i]->Channel(i);
            ui->tabWidget->widget(0)->layout()->addWidget(CF[i]);
        }
    }
    

    I know it can't work. I can't use the function CF.resize() How can I resize the size of the widget's array? Are there any clues? Thank you

    J 1 Reply Last reply 23 Aug 2022, 09:36
    0
    • M mimamrafi
      23 Aug 2022, 09:31

      Hi everyone, I'm sorry about this newbie's question. I want to resize the widget's array, this is my latest codes

      //maingui.h
      #include "channelframe.h"
      ...
      private:
          Ui::MainGUI *ui;
          ChannelFrame *CF[8];
      
      //maingui.cpp
      MainGUI::MainGUI(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainGUI)
      {
          ui->setupUi(this);
      
          ui->tabWidget->widget(0)->setLayout(new QVBoxLayout);
          CF.resize (9);
          const uint array_size = sizeof(CF)/sizeof(CF[0]);
          for (uint i = 0; i < array_size; i++)
          {
              CF[i] = new ChannelFrame;
              connect(CF[i], &ChannelFrame::Next, this, &MainGUI::NextFocus);
              CF[i]->Channel(i);
              ui->tabWidget->widget(0)->layout()->addWidget(CF[i]);
          }
      }
      

      I know it can't work. I can't use the function CF.resize() How can I resize the size of the widget's array? Are there any clues? Thank you

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 23 Aug 2022, 09:36 last edited by
      #2

      @mimamrafi You can't resize an array. Use QVector instead.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 23 Aug 2022, 09:53
      3
      • J jsulm
        23 Aug 2022, 09:36

        @mimamrafi You can't resize an array. Use QVector instead.

        M Offline
        M Offline
        mimamrafi
        wrote on 23 Aug 2022, 09:53 last edited by
        #3

        @jsulm said in Resize of widget's array:

        @mimamrafi You can't resize an array. Use QVector instead.

        Now it's work, Thanks. This is my latest code

        //maingui.h
        #include "channelframe.h"
        ...
        private:
            Ui::MainGUI *ui;
           QVector<ChannelFrame*> CF;
        
        //maingui.cpp
        MainGUI::MainGUI(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainGUI)
        {
            ui->setupUi(this);
        
            ui->tabWidget->widget(0)->setLayout(new QVBoxLayout);
            CF.resize(8);
            for (int i = 0; i < CF.size(); i++)
            {
                CF[i] = new ChannelFrame;
                connect(CF[i], &ChannelFrame::Next, this, &MainGUI::NextFocus);
                CF[i]->Channel(i);
                ui->tabWidget->widget(0)->layout()->addWidget(CF[i]);
            }
        }
        
        1 Reply Last reply
        0

        1/3

        23 Aug 2022, 09:31

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved