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. creating layout in function

creating layout in function

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 3.1k Views 3 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by user4592357
    #1

    i have a widget subclass on which i'm setting a layout. in this layout i have many other layouts. i'm creating all these layouts in my subclass ctor, adding them to main layout and setting it to the widget.

    however, one of the layouts is created in a function. i do it like this: i have a member widget (another one). i init this widget in ctor, then, in layout creating function (the separate one), when the layout is created, i set the layout to the member widget.

    then, in ctor, this widget gets added to the main layout. however, the tab order between widgets is now broken. if i take the code from function and paste it in ctor, everything works fine. so what's the problem with function version?

    and the layout that was created in function gets focus AFTER the layout that's created after it in ctor

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use QWidget::setTabOrder.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        i know about it. i've tried that and it doesn't work

        JonBJ 1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Also as a note.
          The only real difference between ctor and a function is that in function,
          the widgets have been showed first time and all layouts been calculated and
          also tabOrder been established.

          When in ctor, some calculations are are
          delayed until first shown as some widget could be hidden etc.

          But if you call the function from the ctor. it should do the same.
          Its not clear how you call function but I assume you did not call it
          from ctor but say from a button ?

          1 Reply Last reply
          0
          • U Offline
            U Offline
            user4592357
            wrote on last edited by user4592357
            #5

            it's a call from a ctor, returning void.

            i also tried returning the layout from the function and setting it to my member widget but that didn't work either.

            only when i copy paste function code in ctor, it works

            mrjjM 1 Reply Last reply
            0
            • U user4592357

              it's a call from a ctor, returning void.

              i also tried returning the layout from the function and setting it to my member widget but that didn't work either.

              only when i copy paste function code in ctor, it works

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @user4592357
              That is a bit odd as calling a function from ctor should by all means be the same as code
              directly there.
              There must have been a slight difference in what it did. function vs code directly.

              U 1 Reply Last reply
              0
              • mrjjM mrjj

                @user4592357
                That is a bit odd as calling a function from ctor should by all means be the same as code
                directly there.
                There must have been a slight difference in what it did. function vs code directly.

                U Offline
                U Offline
                user4592357
                wrote on last edited by
                #7

                @mrjj

                say i have 3 hlayouts in main vlayout:

                1st hlayout - created in ctir
                2nd hlayout - created in function
                3rd hlayout - created in ctor
                all layouts added to main vlayout
                set vlayout as widget's layout

                in this scenario, say i have a line edit in 1st layout. the tab then goes to 3rd layout, traverses the items, then goes to 2nd layout.

                mrjjM 1 Reply Last reply
                0
                • U user4592357

                  @mrjj

                  say i have 3 hlayouts in main vlayout:

                  1st hlayout - created in ctir
                  2nd hlayout - created in function
                  3rd hlayout - created in ctor
                  all layouts added to main vlayout
                  set vlayout as widget's layout

                  in this scenario, say i have a line edit in 1st layout. the tab then goes to 3rd layout, traverses the items, then goes to 2nd layout.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @user4592357
                  well it sounds like 2nd layout is considered added last.
                  Are you sure function does 100% the same as when u paste the code ?
                  Is that same code completely ?

                  U 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @user4592357
                    well it sounds like 2nd layout is considered added last.
                    Are you sure function does 100% the same as when u paste the code ?
                    Is that same code completely ?

                    U Offline
                    U Offline
                    user4592357
                    wrote on last edited by
                    #9

                    @mrjj

                    yes it's the same code.

                    btw the layout (2nd) is a member, and i create it in the function.

                    1 Reply Last reply
                    0
                    • U user4592357

                      i know about it. i've tried that and it doesn't work

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @SGaist said in creating layout in function:

                      Hi,

                      You can use QWidget::setTabOrder.

                      @user4592357 said in creating layout in function:

                      i know about it. i've tried that and it doesn't work

                      If you still wish to address your issue, I find it hard to believe/surprising that you say QWidget::setTabOrder "doesn't work". Where did you put the calls (e.g. before or after adding them to layouts, before/after adding layouts to layouts --- I would suggest calling it as late as possible, after everything has been created & set up) against which widgets? Who are the parents of the widgets, etc.? Since you say the situation is so simple, you can presumably recreate it in a simple standalone case, without worrying about anything else your existing code might be doing?

                      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