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. (SOLVED) Any way to get how many widgets are in an QVBoxLayout?
QtWS25 Last Chance

(SOLVED) Any way to get how many widgets are in an QVBoxLayout?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.9k 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.
  • J Offline
    J Offline
    jjan
    wrote on last edited by jjan
    #1

    Hi all,
    I have an QVBoxLayout, where Widgets will be added at run time. When I click a button I want to print out how many Widgets are in this Layout. Is this possible? Is there an function such like getWidgets() or so?

    ~ jan

    1 Reply Last reply
    0
    • S Offline
      S Offline
      supaiku_
      wrote on last edited by
      #2

      Use count() to get the number of widgets.

      J 1 Reply Last reply
      1
      • S supaiku_

        Use count() to get the number of widgets.

        J Offline
        J Offline
        jjan
        wrote on last edited by
        #3

        @supaiku-desu (and all others)

        Is there also an way to get the Name of the widget?

        p3c0P 1 Reply Last reply
        0
        • J jjan

          @supaiku-desu (and all others)

          Is there also an way to get the Name of the widget?

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @jjan You can use itemAt to get the QLayoutItem at particular index and use widget to get the widget it contains. Then as usual you can use objectName to get the name of it. Eg:

          ui->verticalLayout->itemAt(1)->widget()->objectName(); //will give name of widget at index 1
          //verticalLayout = QVBoxLayout
          

          157

          J 1 Reply Last reply
          1
          • p3c0P p3c0

            @jjan You can use itemAt to get the QLayoutItem at particular index and use widget to get the widget it contains. Then as usual you can use objectName to get the name of it. Eg:

            ui->verticalLayout->itemAt(1)->widget()->objectName(); //will give name of widget at index 1
            //verticalLayout = QVBoxLayout
            
            J Offline
            J Offline
            jjan
            wrote on last edited by
            #5

            @p3c0

            Many thanks!

            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