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
Qt 6.11 is out! See what's new in the release blog

Resize of widget's array

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 427 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 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

    jsulmJ 1 Reply Last reply
    0
    • M mimamrafi

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      3
      • jsulmJ jsulm

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

        M Offline
        M Offline
        mimamrafi
        wrote on 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

        • Login

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