Vertical QLabel, or the equivalent?

前端 未结 5 2199
执念已碎
执念已碎 2021-01-04 03:53

I want axis labels for a plot I\'m making, and naturally the y-axis label should be oriented vertically. I\'m pretty sure QwtPlot does this, but I\'m trying to

5条回答
  •  隐瞒了意图╮
    2021-01-04 04:52

    So indeed I gave up on finding any simple way to achieve this, and looking over Uwe Rathmann's Qwt code indeed he uses QPainter::drawText() in his QwtPainter::drawText wrapper function, and a QTransform to achieve the rotation, in QwtScaleDraw::labelTransformation. So I've just put these together as follows:

    void LabelWidget::paintEvent(QPaintEvent*)
    {
        QPainter painter(this);
        painter.setPen(Qt::black);
        //... Need an appropriate call to painter.translate() for this to work properly
        painter.rotate(90);
        painter.drawText(QPoint(0,0), _text);
    }
    

    Didn't need a QPixmap, it turns out.

提交回复
热议问题