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 get the widget from QScrollArea with the index of widget?
Forum Updated to NodeBB v4.3 + New Features

How to get the widget from QScrollArea with the index of widget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 902 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.
  • M Offline
    M Offline
    Mikiqueen
    wrote on 13 May 2023, 09:55 last edited by
    #1

    How to get the widget from QScrollArea with the index of the widget in scroll area? I have the index of widget and want to delete it from the scrollArea. But I can't find any solution.

    J C 2 Replies Last reply 13 May 2023, 10:18
    0
    • M Mikiqueen
      13 May 2023, 09:55

      How to get the widget from QScrollArea with the index of the widget in scroll area? I have the index of widget and want to delete it from the scrollArea. But I can't find any solution.

      J Offline
      J Offline
      JonB
      wrote on 13 May 2023, 10:18 last edited by JonB
      #2

      @Mikiqueen
      What index? Do you mean you have added widgets to a layout and want to remove one of them?

      Or, every QObject can use findChild() to try to find a particular child. is that relevant?

      1 Reply Last reply
      3
      • M Mikiqueen
        13 May 2023, 09:55

        How to get the widget from QScrollArea with the index of the widget in scroll area? I have the index of widget and want to delete it from the scrollArea. But I can't find any solution.

        C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 13 May 2023, 10:45 last edited by
        #3

        @Mikiqueen QScrollArea only holds one widget so there is no index. That widget can have children, but their order is unspecified. A widget can have layout set and you can get a layout element with specified index. From layout element you can get a widget it hosts if it has any.

        Whether that's what you want or not I couldn't tell you. You didn't say where that index you have comes from.

        M 1 Reply Last reply 13 May 2023, 12:12
        4
        • C Chris Kawa
          13 May 2023, 10:45

          @Mikiqueen QScrollArea only holds one widget so there is no index. That widget can have children, but their order is unspecified. A widget can have layout set and you can get a layout element with specified index. From layout element you can get a widget it hosts if it has any.

          Whether that's what you want or not I couldn't tell you. You didn't say where that index you have comes from.

          M Offline
          M Offline
          Mikiqueen
          wrote on 13 May 2023, 12:12 last edited by
          #4

          @Chris-Kawa I get the index from the order I add widget to scroll area (I track and store the index of widget added order). Thank you so much I use .itemAt(index) to locate the widget.

          J 1 Reply Last reply 13 May 2023, 12:56
          0
          • M Mikiqueen
            13 May 2023, 12:12

            @Chris-Kawa I get the index from the order I add widget to scroll area (I track and store the index of widget added order). Thank you so much I use .itemAt(index) to locate the widget.

            J Offline
            J Offline
            JonB
            wrote on 13 May 2023, 12:56 last edited by JonB
            #5

            @Mikiqueen said in How to get the widget from QScrollArea with the index of widget?:

            I get the index from the order I add widget to scroll area (I track and store the index of widget added order).

            @Chris-Kawa said in How to get the widget from QScrollArea with the index of widget?:

            @Mikiqueen QScrollArea only holds one widget so there is no index.

            Since you can't add multiple widgets to a QScrollArea

            The QScrollArea class provides a scrolling view onto another widget

            A scroll area is used to display the contents of a child widget within a frame. [...] The child widget must be specified with setWidget()

            void QScrollArea::setWidget(QWidget *widget)

            Sets the scroll area's widget.

            In view of the above (i.e. one widget) don't you think you had better show (a minimal example of) how you add all these widgets:

            I get the index from the order I add widget to scroll area (I track and store the index of widget added order).

            I use .itemAt(index) to locate the widget

            QScrollArea does not have any itemAt().

            M 1 Reply Last reply 13 May 2023, 15:00
            0
            • J JonB
              13 May 2023, 12:56

              @Mikiqueen said in How to get the widget from QScrollArea with the index of widget?:

              I get the index from the order I add widget to scroll area (I track and store the index of widget added order).

              @Chris-Kawa said in How to get the widget from QScrollArea with the index of widget?:

              @Mikiqueen QScrollArea only holds one widget so there is no index.

              Since you can't add multiple widgets to a QScrollArea

              The QScrollArea class provides a scrolling view onto another widget

              A scroll area is used to display the contents of a child widget within a frame. [...] The child widget must be specified with setWidget()

              void QScrollArea::setWidget(QWidget *widget)

              Sets the scroll area's widget.

              In view of the above (i.e. one widget) don't you think you had better show (a minimal example of) how you add all these widgets:

              I get the index from the order I add widget to scroll area (I track and store the index of widget added order).

              I use .itemAt(index) to locate the widget

              QScrollArea does not have any itemAt().

              M Offline
              M Offline
              Mikiqueen
              wrote on 13 May 2023, 15:00 last edited by
              #6

              @JonB Oh I understand now. Thanks for your reply. I'm so new to this tools so there are so many things I don't fully understand

              1 Reply Last reply
              0

              1/6

              13 May 2023, 09:55

              • Login

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