How to align widgets with different types in a QHBoxLayout ?
-
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.
-
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.
@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 aQChartView
? Try a different widget. Are the widgets too wide to fit side by side? You could try them in aQGridLayout
in separate columns just to see whether that works. -
@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 aQChartView
? Try a different widget. Are the widgets too wide to fit side by side? You could try them in aQGridLayout
in separate columns just to see whether that works. -
@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.
Hi,
You are not showing enough code that would explain your issue.
Please provide a minimal compilable example that demonstrate your issue.
-
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.
@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. -
-
@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 aQChartView
? Try a different widget. Are the widgets too wide to fit side by side? You could try them in aQGridLayout
in separate columns just to see whether that works.