Hi Marcel,
I try to draw a polygon on the main widget.
Here's the code i've used. It gave me in the debug-version a segmentation fault...
Poly.h:
#ifndef POLYIMPL_H
#define POLYIMPL_H
#include <QWidget>
#include "ui_poly.h" /* designer made*/
class QPaintEvent;
class QPainter;
class QPolygon;
class PolyImpl:ublic QMainWindow, public Ui::Poly
{
Q_OBJECT
public:
PolyImpl(QWidget *parent = 0, Qt::WFlags f = 0);
protected:
void paintEvent(QPaintEvent *);
private:
QPainter *painter;
QPolygon polygoon;
};
#endif
polyimpl.cpp:
#include <QtGui>
#include "polyImpl.h"
PolyImpl::PolyImpl(QWidget *parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
polygoon << QPoint(10, 10) << QPoint(100, 50) << QPoint(75, 75);
}
void PolyImpl:aintEvent(QPaintEvent *)
{
painter->begin(this);
painter->drawPolygon(polygoon);
painter->end();
}
main.cpp:
#include <QApplication>
#include "polyImpl.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
PolyImpl win;
win.show();
app.connect(&app, SIGNAL(lasWindowClosed()), &app, SLOT(quit()));
return app.exec();
}
Bookmarks