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. Can't configure properly my layouts
Forum Updated to NodeBB v4.3 + New Features

Can't configure properly my layouts

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.7k 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.
  • P Offline
    P Offline
    PP_RhuM
    wrote on last edited by
    #1

    I created with QT designer two widgets.
    This one is simple (OperatorPanel), it uses an horizontal layout and a fixed size widget containing itself some sub widgets:
    0_1547652392736_opPanel.jpg

    This other one is most sofisticated (CurveEditorWidget). It uses a vertical layout.
    In this layout, there is :

    • a scrollarea that should expand in both directions
    • an horizontal layout : it contains many sub widgets. All these widgets' height is fixed and their's width is also fixed except for the currentPointFunction_lineEdit widget. Then, this is the only one that should expand horizontally.

    Here is the view in the QT Designer:
    0_1547652757297_curveEditor.jpg

    If I resize it in the QT designer, everything seems nice.

    Now, I add in the OperatorPanel constructor a new CurveEditorWidget using:

    curveEditor_widget = new CurveEditorWidget();
    ui.horizontalLayout->addWidget(curveEditor_widget, 0, Qt::AlignLeft);
    curveEditor_widget->show();
    

    Then, I add an OperatorPanel to a main window and I resize it using :

    int width = this->width() - 5;
    myOperatorPanel->setFixedWidth(width);
    

    But it always take the minimum size the widget can use:
    0_1547653019399_association_in_window.jpg

    Note that the widget is added dynamically at a moment when the "width" variable has the expected value (window is painted).

    I certainly didn't try everything because I think there is a solution, but after many tries when configuring my layouts and widgets size policy, I can't realize the expected result and expand the complete widget horizontally.

    I'm sure that if I understand how to perform this, I will work harder on my main window to also use layouts (actually I'm placing in it widgets using absolute positions and setting fixed width on them).

    Anyone can help ?

    Thank you very much.

    K 1 Reply Last reply
    0
    • P PP_RhuM

      I created with QT designer two widgets.
      This one is simple (OperatorPanel), it uses an horizontal layout and a fixed size widget containing itself some sub widgets:
      0_1547652392736_opPanel.jpg

      This other one is most sofisticated (CurveEditorWidget). It uses a vertical layout.
      In this layout, there is :

      • a scrollarea that should expand in both directions
      • an horizontal layout : it contains many sub widgets. All these widgets' height is fixed and their's width is also fixed except for the currentPointFunction_lineEdit widget. Then, this is the only one that should expand horizontally.

      Here is the view in the QT Designer:
      0_1547652757297_curveEditor.jpg

      If I resize it in the QT designer, everything seems nice.

      Now, I add in the OperatorPanel constructor a new CurveEditorWidget using:

      curveEditor_widget = new CurveEditorWidget();
      ui.horizontalLayout->addWidget(curveEditor_widget, 0, Qt::AlignLeft);
      curveEditor_widget->show();
      

      Then, I add an OperatorPanel to a main window and I resize it using :

      int width = this->width() - 5;
      myOperatorPanel->setFixedWidth(width);
      

      But it always take the minimum size the widget can use:
      0_1547653019399_association_in_window.jpg

      Note that the widget is added dynamically at a moment when the "width" variable has the expected value (window is painted).

      I certainly didn't try everything because I think there is a solution, but after many tries when configuring my layouts and widgets size policy, I can't realize the expected result and expand the complete widget horizontally.

      I'm sure that if I understand how to perform this, I will work harder on my main window to also use layouts (actually I'm placing in it widgets using absolute positions and setting fixed width on them).

      Anyone can help ?

      Thank you very much.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @PP_RhuM

      Hi and welcome to devnet forum

      Looks like the hosting widget where you are placing the 2 widget does not have a layout assigned.

      How do you create the hosting widget?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      1
      • P Offline
        P Offline
        PP_RhuM
        wrote on last edited by
        #3

        Hi and thank you for your help.

        The CurveEditorWidget widget is added to the OperatorPanel widget, which uses an horizontal layout (can see it in the inspector of QT Designer).

        Then, the OperatorPanel widget is added to a main window and its size is changed through the "setFixedWidth" function.

        K JonBJ 2 Replies Last reply
        0
        • P PP_RhuM

          Hi and thank you for your help.

          The CurveEditorWidget widget is added to the OperatorPanel widget, which uses an horizontal layout (can see it in the inspector of QT Designer).

          Then, the OperatorPanel widget is added to a main window and its size is changed through the "setFixedWidth" function.

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @PP_RhuM

          From the attached picture one cannot see what is around, but typically you can select the MainWindow with its whole content in designer and apply a layout and you are done.

          When you do this code, you have to add a layout and fit both widgets into it.

          From personal experience I recommend playing around in Qt designer (add a form in Qt creator) a bit. When you are satisfied with the outcome, you can moc the result and checkout the generated code.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          1
          • P PP_RhuM

            Hi and thank you for your help.

            The CurveEditorWidget widget is added to the OperatorPanel widget, which uses an horizontal layout (can see it in the inspector of QT Designer).

            Then, the OperatorPanel widget is added to a main window and its size is changed through the "setFixedWidth" function.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @PP_RhuM
            Maybe I'm misunderstanding. If you want your/one/a widget to expand to fit its parent horizontally, have you ensured your widget has something like setSizePolicy(QSizePolicy::MinimumExpanding, ...) (http://doc.qt.io/qt-5/qwidget.html#setSizePolicy-1)? You don't care about fixed sizes or resizing or when you add it to its container then.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PP_RhuM
              wrote on last edited by PP_RhuM
              #6

              I Changed a little thing: I added all my controls (in the bottom of the CurveEditorWidget) in a simple widget container (see in the inspector) :
              0_1547658153864_curveEditor_2.jpg

              In the structure, here are size policy (H / V):

              • CurveEditorWidget = MinimumExpanding / Prefered
              • curve_scrollArea = Expanding / Expanding
              • optionsContainer_widget = MinimumExpanding / Prefered
              • currentPointFunction_lineEdit = MinimumExpanding / Fixed
              • All other widgets under optionsContainer_widget = Fixed / Fixed

              For the OperatorPanel widget:

              • OperatorPanel = MinimumExpanding / Prefered
              • pitchDials_widget = Maximum / Fixed
              • All other widgets under pitchDials_widget = Fixed / Fixed

              I change the width of the instance of the OperatorPanel added dynamically to the main window. It's not placed in a layout, it's placed in the main window itself and positionned in an absolute place.

              Should i add another container to embed the operator panel widget like this ?

              QWidget *container = new QWidget(this);
              QHBoxLayout *container_hLayout = new QHBoxLayout(container);
              container_hLayout->addWidget(operatorPanel);
              container->setFixedWidth(this->width() - 5);
              

              It doesn't make really sense because the OperatorPanel widget should be sizable with size I want..

              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