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. Designing a custom widget
QtWS25 Last Chance

Designing a custom widget

Scheduled Pinned Locked Moved Solved General and Desktop
designdesign patternc++
5 Posts 2 Posters 530 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.
  • D Offline
    D Offline
    Daniel_Contro
    wrote on 28 May 2020, 07:34 last edited by
    #1

    Hello,
    I was wondering if in general it's better to design a custom widget containing a pointer for each sub widget/layout allocated in the heap or gather the various pointers using QWidget methods and allocate sub widget only inside methods, taking advantage of parent/child relations, without having a direct reference to them.
    In particular, in my custom widget I need to add and remove specific widgets.

    J 1 Reply Last reply 28 May 2020, 07:39
    0
    • D Daniel_Contro
      28 May 2020, 07:34

      Hello,
      I was wondering if in general it's better to design a custom widget containing a pointer for each sub widget/layout allocated in the heap or gather the various pointers using QWidget methods and allocate sub widget only inside methods, taking advantage of parent/child relations, without having a direct reference to them.
      In particular, in my custom widget I need to add and remove specific widgets.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 28 May 2020, 07:39 last edited by
      #2

      @Daniel_Contro If you need to access the widgets later then it is better to store the pointers as members in your class.

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

      D 1 Reply Last reply 28 May 2020, 07:59
      0
      • J jsulm
        28 May 2020, 07:39

        @Daniel_Contro If you need to access the widgets later then it is better to store the pointers as members in your class.

        D Offline
        D Offline
        Daniel_Contro
        wrote on 28 May 2020, 07:59 last edited by
        #3

        @jsulm Even if the insert/remove of widgets would occur only upon mouse events? I would then use childAt(event->pos()) to gather the pointer and not the member in the class.

        J 1 Reply Last reply 28 May 2020, 08:01
        0
        • D Daniel_Contro
          28 May 2020, 07:59

          @jsulm Even if the insert/remove of widgets would occur only upon mouse events? I would then use childAt(event->pos()) to gather the pointer and not the member in the class.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 28 May 2020, 08:01 last edited by
          #4

          @Daniel_Contro Well, if your UI is so dynamic then you can of course use childAt, but keep in mind that it is not very fast (you should not call it in long lasting loops for example).

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

          D 1 Reply Last reply 28 May 2020, 08:12
          0
          • J jsulm
            28 May 2020, 08:01

            @Daniel_Contro Well, if your UI is so dynamic then you can of course use childAt, but keep in mind that it is not very fast (you should not call it in long lasting loops for example).

            D Offline
            D Offline
            Daniel_Contro
            wrote on 28 May 2020, 08:12 last edited by
            #5

            @jsulm Ok, thanks a lot for the help

            1 Reply Last reply
            0

            5/5

            28 May 2020, 08:12

            • Login

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