First you have to translate the painter! See here:
#include <QtGui>
{
public:
{
rect
= QRect(0,
0,
100,
100);
}
{
return rect.size();
}
protected:
{
Q_UNUSED(event);
p.
setRenderHint(QPainter::Antialiasing,
true);
p.drawEllipse(rect);
p.save();
p.translate(rect.center());
p.rotate(15);
p.
drawRect(QRect(-20,
-10,
40,
20));
p.restore();
}
private:
};
int main(int argc, char* argv[])
{
Compass c;
c.show();
return a.exec();
}
#include <QtGui>
class Compass : public QWidget
{
public:
Compass(QWidget* parent = 0) : QWidget(parent)
{
rect = QRect(0, 0, 100, 100);
}
QSize sizeHint() const
{
return rect.size();
}
protected:
void paintEvent(QPaintEvent* event)
{
Q_UNUSED(event);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing, true);
p.drawEllipse(rect);
p.save();
p.translate(rect.center());
p.rotate(15);
p.drawRect(QRect(-20, -10, 40, 20));
p.restore();
}
private:
QRect rect;
};
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
Compass c;
c.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks