QCustomPlot Discussion and Comments

write yAxis->setLabel() horizontally, not verticallyReturn to overview

Hi, I'm new to qcustomplot and am having trouble with putting the y-axis text horizontally. I have at least 12 graphs showing in the customplot and I would like to have them all be self contained. In other words, each of these graphs will be able to hide and move to different positions so I want everything self contained for each graph. The way I tried to accomplished this was to use two subRects. The first would be positioned to have the greatest size available and the y-axis text written in it. The second would then be the actual graph. I do get most of it to work but the graph is now really small, but other than that, it looks like it would be correct.

    customPlots->plotLayout()->addElement( 0, 0, subLayout ); 
    QCPAxisRect *subRect0 = new QCPAxisRect( customPlots, false ); 
    QCPAxisRect *subRect20 = new QCPAxisRect( customPlots, false ); 
    subLayout->addElement( 0, 0, subRect0 );
    subRect0->insetLayout()->addElement( subRect20, Qt::AlignLeft );
   
    subRect20->setAutoMargins( QCP::msTop| QCP::msRight | QCP::msBottom );
    subRect20->setMargins( QMargins(55,0,0,0) );
    subRect20->addAxes( QCPAxis::atBottom | QCPAxis::atLeft );
    subRect20->axis( QCPAxis::atBottom )->setTicks( false );
    subRect20->axis( QCPAxis::atLeft )->setTicks( false );
    QCPGraph *graph0 = customPlots->addGraph( subRect20->axis(QCPAxis::atBottom),subRect20->axis(QCPAxis::atLeft) );
    graph0->setData( index_x, index_y );
    graph0->rescaleAxes();

    // add the text label at the left(y axis):
    QCPItemText *textLabel = new QCPItemText( customPlots );
    customPlots->addItem( textLabel );
    textLabel->setClipToAxisRect( false );
    textLabel->setClipAxisRect( subRect0 );
    textLabel->setPositionAlignment( Qt::AlignLeft|Qt::AlignHCenter );
    textLabel->position->setType( QCPItemPosition:: ptAxisRectRatio );//ptAbsolute
    textLabel->position->setAxisRect( subRect0 );
    textLabel->position->setCoords( 0, 0 ); // place position at center/top of axis rect
    textLabel->setText( "Index" );
    textLabel->setFont( QFont(QFont().family(), 8) ); // make font a bit larger
}

I know I'm doing something wrong so if anyone could give me a heads up, I would appreciate it.

Thanks

If you only want to have axis labels horizontally, you might rather subclass QCPAxisPainterPrivate and reimplement the ::draw/::size methods. There the axis label is drawn rotated. The ::size method needs the correction if you want to use automatic axis margins. If you do that, you'll also need to subclass QCPAxis to make it use your new axis painter subclass (create and set it in the constructor).

I'm not quite sure what you are trying to achieve with the sub layout, axis rects and inset layout. Maybe I didn't quite get what you're trying to do?

Hello everybody.
I must say thanks for your help in advance.
My question is I can't find addItem function in my qCustomPlot!!
What can I do?
Exactly this line:

customPlots->addItem( textLabel );