QCustomPlot Discussion and Comments

Align from top QCPItemTextReturn to overview

Hi!

I'm trying to align QCPItemText from the top axis when I rotate it 90 degrees but my labels have different sizes.
As you can see on the image, it has some E 135 and another is E 65.

The label is padding from the top, but I want them to all align from top.
Here is my code :

// add the text label at the top:
        QCPItemText *label = new QCPItemText(this);
        this->addItem(label);
        label->position->setType(QCPItemPosition::ptAxisRectRatio);
        label->setPositionAlignment(Qt::AlignRight|Qt::AlignTop);
        label->setRotation(90);
        label->position->setCoords(ratio, 0.05);

I tried setting

label->position->setTypeY(QCPItemPosition::ptAbsolute)
QCPItemText *label = new QCPItemText(this);
        this->addItem(label);
        label->position->setTypeX(QCPItemPosition::ptAxisRectRatio);
        label->position->setTypeY(QCPItemPosition::ptAbsolute);
        label->setPositionAlignment(Qt::AlignRight|Qt::AlignTop);
        label->setRotation(90);
        label->position->setCoords(ratio, 0.05);

but now the label just disappears

So I don't know what I'm doing wrong.
Any help would be appreciated!

Oops forgot the image, here it is :
https://dl.dropboxusercontent.com/u/11394500/alignment.png

just found out a way :

        // add the text label at the top:
        QCPItemText *label = new QCPItemText(this);
        this->addItem(label);
        label->position->setType(QCPItemPosition::ptAxisRectRatio);
        label->setPositionAlignment(Qt::AlignTop);
        label->setRotation(90);
        label->position->setCoords(ratio, 0);

Thanx!!

Glad you found the right method.

The reason your original attempt with

        label->position->setTypeY(QCPItemPosition::ptAbsolute);
        label->setPositionAlignment(Qt::AlignRight|Qt::AlignTop);
        label->setRotation(90);
        label->position->setCoords(ratio, 0.05);

didn't work is that you're using absolute pixel coordinates for Y, and then set it to 0.05 pixels. So the label will be all the way at the top of the QCustomPlot widget (the absolute origin is in the top left corner of the widget). So it is probably well outside the axis rect. However, if you have clipping enabled, the label is then not visible (setClipToAxisRect was still true on the text item).

@DerManu
Thanx! :D