QCustomPlot Discussion and Comments

Adding QCPTextElement to column 1 shrinks the whole row heightReturn to overview

I have a plot made by several rows.
top row is a fake axis rect used for showing some QCPItemText 's.
the others are axisrects with graphs and they are added as

m_plot->plotLayout()->addElement(i + 1, 0, axisRect);

in a for cycle.

at the bottom I added QCPLayoutElement to make space for bottom axis ticks and labels.

beside axis rects i want to add a text element with the corresponding number of the axis rect

If I add into (i + 1, 1) a QCPLayoutElement then set its maximum and minimum size assigning QWIDGETSIZE_MAX as height, rows height are normally plotted with the right stretch factors.

If I add a QCPTextElement - which is what I really need - instead of a simple QCPLayoutElement - rows are plotted with their heights shrinked.

QCPTextElement *stripNum = new QCPTextElement(m_plot);
stripNum->setSizeConstraintRect(QCPTextElement::SizeConstraintRect::scrOuterRect); // irrilevant
stripNum->setMaximumSize(fixedValue, QWIDGETSIZE_MAX);
stripNum->setMinimumSize(fixedValue, 0);
m_plot->plotLayout()->addElement(i + 1, 1, stripNum);
m_plot->plotLayout()->setRowStretchFactor(i + 1, 1);

why? How can I have my rows plotted correctly with a text element in the second column ?

thank you

I solved my own.
I looked at classes derived from QCPLayoutElement. I used a QCPLayoutInset and put it in the right column. Inside this I put the QCPTextElement.

QCPLayoutInset *stripNumLayout = new QCPLayoutInset();
stripNumLayout->setMaximumSize(fixedValue, QWIDGETSIZE_MAX);
stripNumLayout->setMinimumSize(fixedValue, 0);
QCPTextElement * stripNum = new QCPTextElement(m_plot);
stripNum->setText(QString::number(i + 1));
stripNumLayout->addElement(stripNum, Qt::AlignTop | Qt::AlignLeft);
m_plot->plotLayout()->addElement(i + 1, 1, stripNumLayout)

I think some official examples like this could save much time to others.