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. how i can call func for dynamic created QWidget from MainWindow
Forum Updated to NodeBB v4.3 + New Features

how i can call func for dynamic created QWidget from MainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 399 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    rexha52
    wrote on last edited by
    #1

    hey guys, pls help me
    Im have QWidget class Section
    and button for add Section:

    void MainWindow::on_button_AddZone_clicked()
    {
        new_zone_name="Place #";
        QString name=new_zone_name+QString::number(++ui::Section::zone_count);
        section = new ui::Section(name,300, ui->centralWidget);
        ui->centralWidget->layout()->addWidget(section);
        auto* anyLayout = new QVBoxLayout();
        anyLayout->addWidget(new QLabel("Some Text in Section", section));
        anyLayout->addWidget(new QTableView(section));
        section->setContentLayout(*anyLayout);
    }
    

    and Section have some function

    public slots:
           void toggle(bool collapsed);
    

    how i can call this func for ALL created by button QWidget from MainWindwow?
    how i can call this func for definetely QWidget? (I can use some ID and etc???)

    Thank you!

    JonBJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      Connect all your Section objects to receive a toogle signal emitted by the MainWindow.

      Overall your code is strange ...

      1 Reply Last reply
      1
      • R rexha52

        hey guys, pls help me
        Im have QWidget class Section
        and button for add Section:

        void MainWindow::on_button_AddZone_clicked()
        {
            new_zone_name="Place #";
            QString name=new_zone_name+QString::number(++ui::Section::zone_count);
            section = new ui::Section(name,300, ui->centralWidget);
            ui->centralWidget->layout()->addWidget(section);
            auto* anyLayout = new QVBoxLayout();
            anyLayout->addWidget(new QLabel("Some Text in Section", section));
            anyLayout->addWidget(new QTableView(section));
            section->setContentLayout(*anyLayout);
        }
        

        and Section have some function

        public slots:
               void toggle(bool collapsed);
        

        how i can call this func for ALL created by button QWidget from MainWindwow?
        how i can call this func for definetely QWidget? (I can use some ID and etc???)

        Thank you!

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @rexha52 said in how i can call func for dynamic created QWidget from MainWindow:

        how i can call this func for ALL created by button QWidget from MainWindwow?

        If you mean call it once at creation time you can call a public slot directly: section->toggle(true);. If you mean in response to later signal do connect() as @mpergand says.

        how i can call this func for definetely QWidget? (I can use some ID and etc???)

        I cannot understand this sentence.

        R 1 Reply Last reply
        1
        • JonBJ JonB

          @rexha52 said in how i can call func for dynamic created QWidget from MainWindow:

          how i can call this func for ALL created by button QWidget from MainWindwow?

          If you mean call it once at creation time you can call a public slot directly: section->toggle(true);. If you mean in response to later signal do connect() as @mpergand says.

          how i can call this func for definetely QWidget? (I can use some ID and etc???)

          I cannot understand this sentence.

          R Offline
          R Offline
          rexha52
          wrote on last edited by
          #4

          @JonB https://recordit.co/Lo7FO1VnA9
          when im click ADD BUTTON it create a widget from class Section. Every Section have some other widget(table, button, lavel etc)
          when im created 5 Sections, how i can read some values or call some function from a certain Section, for example for QLabel in second Section? or in last created Section?

          jsulmJ JonBJ 2 Replies Last reply
          0
          • R rexha52

            @JonB https://recordit.co/Lo7FO1VnA9
            when im click ADD BUTTON it create a widget from class Section. Every Section have some other widget(table, button, lavel etc)
            when im created 5 Sections, how i can read some values or call some function from a certain Section, for example for QLabel in second Section? or in last created Section?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @rexha52 said in how i can call func for dynamic created QWidget from MainWindow:

            when im created 5 Sections, how i can read some values or call some function from a certain Section

            Please show how you're creating those Section instances

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

            1 Reply Last reply
            1
            • R rexha52

              @JonB https://recordit.co/Lo7FO1VnA9
              when im click ADD BUTTON it create a widget from class Section. Every Section have some other widget(table, button, lavel etc)
              when im created 5 Sections, how i can read some values or call some function from a certain Section, for example for QLabel in second Section? or in last created Section?

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @rexha52
              As @jsulm has responded. If you have a "list" of things, store & access them in an array/list. Nothing more to say.

              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