I have subclassed the QCustomPlot class to add some functionality. In the new constructor, I place the legend in a new QCPLayoutGrid below the graph as explained in the documentation:
QCPLayoutGrid *sub_layout = new QCPLayoutGrid; this->plotLayout()->addElement(1, 0, sub_layout); sub_layout->setMargins(QMargins(5, 0, 5, 5)); sub_layout->addElement(0, 0, this->legend); this->plotLayout()->setRowStretchFactor(1, 1e-10); // Make legend row as small in height as possible
However, adding the element causes the graph area width to reduce to about 10% of its original size. The full width is restored as soon as I plot some data, but I want the empty graph to be full-width as well.
The problem: https://pasteboard.co/v5b7UBYvF7cc.png
How I want it to be: https://pasteboard.co/dezhKVbqQwaC.png