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 align widgets with different types in a QHBoxLayout ?
Forum Updated to NodeBB v4.3 + New Features

How to align widgets with different types in a QHBoxLayout ?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 652 Views 2 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.
  • A Offline
    A Offline
    Aminsl
    wrote on last edited by
    #1

    I'm working with a QGraphicsScene and I've created a ChartView dynamically that contains a QChart . I've also created a widget design file with named controlchart with controlchart.ui file. I'm trying to align them in a QHBoxLayout in order to have them in a horizontal way next to each other but they render above each other. I've tried to change the alignment of the layout but it didn't work out.
    Here is my code :

    ChartView *chartView = new ChartView(m_chart);
    chartView->setRenderHint(QPainter::Antialiasing);
    
    ControlChart *clrChart = new ControlChart();
    
    QHBoxLayout *mBoxLayout = new QHBoxLayout(this);
    mBoxLayout -> addWidget(chartView);
    mBoxLayout -> addWidget(clrChart);
    
    setLayout(mBoxLayout);
    

    Clearly , the controlchart type is QWidget.

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • A Aminsl

      I'm working with a QGraphicsScene and I've created a ChartView dynamically that contains a QChart . I've also created a widget design file with named controlchart with controlchart.ui file. I'm trying to align them in a QHBoxLayout in order to have them in a horizontal way next to each other but they render above each other. I've tried to change the alignment of the layout but it didn't work out.
      Here is my code :

      ChartView *chartView = new ChartView(m_chart);
      chartView->setRenderHint(QPainter::Antialiasing);
      
      ControlChart *clrChart = new ControlChart();
      
      QHBoxLayout *mBoxLayout = new QHBoxLayout(this);
      mBoxLayout -> addWidget(chartView);
      mBoxLayout -> addWidget(clrChart);
      
      setLayout(mBoxLayout);
      

      Clearly , the controlchart type is QWidget.

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

      @Aminsl
      [Not sure what the relevance of your "QGraphicsScene " is] In principle mixed widget types are fine in a layout. Is there some specific issue because it's a QChartView? Try a different widget. Are the widgets too wide to fit side by side? You could try them in a QGridLayout in separate columns just to see whether that works.

      A 2 Replies Last reply
      1
      • JonBJ JonB

        @Aminsl
        [Not sure what the relevance of your "QGraphicsScene " is] In principle mixed widget types are fine in a layout. Is there some specific issue because it's a QChartView? Try a different widget. Are the widgets too wide to fit side by side? You could try them in a QGridLayout in separate columns just to see whether that works.

        A Offline
        A Offline
        Aminsl
        wrote on last edited by
        #3

        @JonB I will try it . I know that different types are fine with a layout but still I don't know why those widgets can't align in a horizontal order and always render like a stack layout.

        SGaistS 1 Reply Last reply
        0
        • A Aminsl

          @JonB I will try it . I know that different types are fine with a layout but still I don't know why those widgets can't align in a horizontal order and always render like a stack layout.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You are not showing enough code that would explain your issue.

          Please provide a minimal compilable example that demonstrate your issue.

          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
          0
          • A Aminsl

            I'm working with a QGraphicsScene and I've created a ChartView dynamically that contains a QChart . I've also created a widget design file with named controlchart with controlchart.ui file. I'm trying to align them in a QHBoxLayout in order to have them in a horizontal way next to each other but they render above each other. I've tried to change the alignment of the layout but it didn't work out.
            Here is my code :

            ChartView *chartView = new ChartView(m_chart);
            chartView->setRenderHint(QPainter::Antialiasing);
            
            ControlChart *clrChart = new ControlChart();
            
            QHBoxLayout *mBoxLayout = new QHBoxLayout(this);
            mBoxLayout -> addWidget(chartView);
            mBoxLayout -> addWidget(clrChart);
            
            setLayout(mBoxLayout);
            

            Clearly , the controlchart type is QWidget.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @Aminsl said in How to align widgets with different types in a QHBoxLayout ?:

            QHBoxLayout *mBoxLayout = new QHBoxLayout(this);
            mBoxLayout -> addWidget(chartView);
            mBoxLayout -> addWidget(clrChart);

            You mention a QGraphicsScene. But this scene is not added to you horizontal layout, at least not in the part you show.
            Could this lead to your issue?!
            Where is your scene placed?
            Because there is no way, that widgets in a horizontal layout are vertical above each other.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • A Aminsl has marked this topic as solved on
            • JonBJ JonB

              @Aminsl
              [Not sure what the relevance of your "QGraphicsScene " is] In principle mixed widget types are fine in a layout. Is there some specific issue because it's a QChartView? Try a different widget. Are the widgets too wide to fit side by side? You could try them in a QGridLayout in separate columns just to see whether that works.

              A Offline
              A Offline
              Aminsl
              wrote on last edited by
              #6

              @JonB GridLayout worked perfectly , thanks :)

              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