[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-edu
Subject: Re: [kde-edu]: Need help with this code
From: Kevin Krammer <kevin.krammer () gmx ! at>
Date: 2005-07-11 17:12:03
Message-ID: 200507111912.08542.kevin.krammer () gmx ! at
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
On Monday 11 July 2005 16:02, Carsten Niehaus wrote:
> I am drawing a vertical line and then want to put a string below that
> line....
>
> =B7 =B7 p->drawLine( x,0,x, m_realHeight );
> =B7 =B7 p->save();
> =B7 =B7 p->rotate( -90.0 );
> =B7 =B7 p->translate( m_realHeight,0 );
You have to translate before you rotate.
See attached exampe.
Cheers,
Kevin
["qdrawtexttest.cpp" (text/x-c++src)]
#include <qapplication.h>
#include <qpainter.h>
#include <qwidget.h>
class Widget : public QWidget
{
public:
Widget() : QWidget(0, "widget") {}
protected:
virtual void paintEvent(QPaintEvent* event)
{
QPainter p(this);
int x = rect().center().x();
int y = rect().center().y();
p.setPen(Qt::blue);
p.drawLine(x, 0, x, height());
p.drawLine(0, y, width(), y);
// draw at center
p.drawText(x, y, "Foo");
// translate into center (center becomes (0, 0))
p.translate(x, y);
// rotate around new (0, 0) (former center)
p.rotate(-90);
// draw at (0, 0) (former center)
p.setPen(Qt::red);
p.drawText(0, 0, "Bar");
}
};
int main(int argc, char** argv)
{
QApplication app(argc, argv);
Widget w;
app.setMainWidget(&w);
w.resize(200, 200);
w.show();
return app.exec();
}
[Attachment #8 (application/pgp-signature)]
_______________________________________________
kde-edu mailing list
kde-edu@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-edu
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic