The goal is to get the legend in a strip above the axisRect and arranged horizontally. This is all I could figure out after a lot of RTFM and trying different approaches. Is there a better way?

    
    plotLayout()->insertRow(0);
    plotLayout()->addElement(0, 0, legend);

    legend->insertRow(0);
    QCPTextElement *legendDummyFirst = new QCPTextElement(this);
    legendDummyFirst->setLayer(legend->layer());
    legendDummyFirst->setText("");
    legend->addElement(0, 0, legendDummyFirst);

    QCPTextElement *legendDummyLast = new QCPTextElement(this);
    legendDummyLast->setLayer(legend->layer());
    legendDummyLast->setText("");
    int legend_element_count = legend->elementCount();
    legend->addElement(legend_element_count, 0, legendDummyLast);

    legend->setFillOrder(QCPLegend::foColumnsFirst);

When updated datasets are plotted, I have to do this:
    clearGraphs();
    legend->clear();

... updated datasets plotted here

    legend->insertColumn(0);
    QCPTextElement *legendDummyFirst = new QCPTextElement(this);
    legendDummyFirst->setLayer(legend->layer());
    legendDummyFirst->setText("");
    legend->addElement(0, 0, legendDummyFirst);

    QCPTextElement *legendDummyLast = new QCPTextElement(this);
    legendDummyLast->setLayer(legend->layer());
    legendDummyLast->setText("");
    int legend_element_count = legend->elementCount();
    legend->addElement(0, legend_element_count, legendDummyLast);