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 to implement multiple , same widgets, in "loop "?
Forum Updated to NodeBB v4.3 + New Features

How to implement multiple , same widgets, in "loop "?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 272 Views 2 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    I have the following test code setting "TEST trace" text in consecutive widgets.

    I am asking for suggestions on how to implement the code using "loop" - in QCreator.

    As an example - I like to be able to "clear()" the text in such loop.

    From other resources - one way to do that is to have "parent widget" and iterate thru children.

    // test tabs
    ui->chat_2->setText("TEST trace ");
    ui->chat_3->setText("TEST trace ");
    ui->chat_4->setText("TEST trace ");
    ui->chat_5->setText("TEST trace ");
    ui->chat_6->setText("TEST trace ");

    CP71C 1 Reply Last reply
    0
    • A Anonymous_Banned275

      I have the following test code setting "TEST trace" text in consecutive widgets.

      I am asking for suggestions on how to implement the code using "loop" - in QCreator.

      As an example - I like to be able to "clear()" the text in such loop.

      From other resources - one way to do that is to have "parent widget" and iterate thru children.

      // test tabs
      ui->chat_2->setText("TEST trace ");
      ui->chat_3->setText("TEST trace ");
      ui->chat_4->setText("TEST trace ");
      ui->chat_5->setText("TEST trace ");
      ui->chat_6->setText("TEST trace ");

      CP71C Offline
      CP71C Offline
      CP71
      wrote on last edited by CP71
      #2

      @AnneRanch
      Hi
      like this!

      QList<QPushButton*> pushButtons = findChildren<QPushButton*>();
      foreach (QPushButton*pBut, pushButtons) {
          if ( pBut )
          {
              pBut->setText("HI");
          }
      }
      

      here is only an example!

      A 1 Reply Last reply
      4
      • CP71C CP71

        @AnneRanch
        Hi
        like this!

        QList<QPushButton*> pushButtons = findChildren<QPushButton*>();
        foreach (QPushButton*pBut, pushButtons) {
            if ( pBut )
            {
                pBut->setText("HI");
            }
        }
        

        here is only an example!

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @CP71 Thanks, works perfectly.

        1 Reply Last reply
        1

        • Login

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