Vertical QLabel, or the equivalent?

前端 未结 5 2238
执念已碎
执念已碎 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:37

    Here is a variant of Mostafa's implementation.

    void VerticalLabel::paintEvent(QPaintEvent*)
    {
        QPainter painter(this);
    
    //    painter.translate(sizeHint().width(),0);
    //    painter.rotate(90);
        painter.translate(0,sizeHint().height());
        painter.rotate(270);
    
        painter.drawText(QRect (QPoint(0,0),QLabel::sizeHint()),Qt::AlignCenter,text());
    }
    

    basically i have removed setPen and setBrush to preserve stylesheet and i have used an overload of drawText that uses the rect instead of point. This allows to have the '\n' inside the text or use WordWrap as a flag.

提交回复
热议问题