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 527 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 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.

    jsulmJ 1 Reply Last reply
    0
    • D Daniel_Contro

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      0
      • jsulmJ jsulm

        @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 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.

        jsulmJ 1 Reply Last reply
        0
        • D Daniel_Contro

          @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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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
          0
          • jsulmJ jsulm

            @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 last edited by
            #5

            @jsulm Ok, thanks a lot for the help

            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