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
try using this:
#ifndef VERTICALLABEL_H
#define VERTICALLABEL_H
#include
class VerticalLabel : public QLabel
{
Q_OBJECT
public:
explicit VerticalLabel(QWidget *parent=0);
explicit VerticalLabel(const QString &text, QWidget *parent=0);
protected:
void paintEvent(QPaintEvent*);
QSize sizeHint() const ;
QSize minimumSizeHint() const;
};
#endif // VERTICALLABEL_H
///cpp
#include "verticallabel.h"
#include
VerticalLabel::VerticalLabel(QWidget *parent)
: QLabel(parent)
{
}
VerticalLabel::VerticalLabel(const QString &text, QWidget *parent)
: QLabel(text, parent)
{
}
void VerticalLabel::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.setPen(Qt::black);
painter.setBrush(Qt::Dense1Pattern);
painter.rotate(90);
painter.drawText(0,0, text());
}
QSize VerticalLabel::minimumSizeHint() const
{
QSize s = QLabel::minimumSizeHint();
return QSize(s.height(), s.width());
}
QSize VerticalLabel::sizeHint() const
{
QSize s = QLabel::sizeHint();
return QSize(s.height(), s.width());
}