Niamita
10th May 2011, 05:56
Hi Experts
I have problem in my painEvent() , the function is get called many times but get nothing draw on the widget.I understand why the function is gett called so much time but how to resolve this.
I am drawing a hexagon
void MainWindow::paintEvent(QPaintEvent *event )
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPen pen(Qt::black);
pen.setWidth(6);
painter.setPen(pen);
static const QPointF points[6] = {
QPointF(300.0, 160.0),//Top Line
QPointF(220.0, 160.0),//
//QPointF(300.0, 180.0),
QPointF(195.0, 210.0),
QPointF(220.0, 260.0),//
QPointF(300.0, 260.0),//Bottom Line
QPointF(325.0, 210.0)
};
painter.drawPolygon(points, 6);
qDebug() << "Cnt=" << cnt;
cnt++;
QPainter painter1(this);
QPen pen1(Qt::green);
painter1.setPen(pen1);
QLinearGradient grad1(300, 160, 325, 260);
QBrush brush1(grad1);
grad1.setColorAt(1.0, Qt::white);
painter1.setBrush(brush1);
QFont font("Times", 12);
painter1.setFont(font);
QPoint point1 = QPoint( 240, 225);
painter1.drawText( point1, text_str );
}
and
NewWindow::NewWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::NewWindow)
{
ui->setupUi(this);
QString string = "Gello";
w1 = new MainWindow(string ,this);
w1->show();
}
Please guide me i am trying to resolve this since 1 day.
Is i have to call paintEvent() manually but i read at a place there is no need to call it manually.
Thanks.
Waiting for your reply.
I have problem in my painEvent() , the function is get called many times but get nothing draw on the widget.I understand why the function is gett called so much time but how to resolve this.
I am drawing a hexagon
void MainWindow::paintEvent(QPaintEvent *event )
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPen pen(Qt::black);
pen.setWidth(6);
painter.setPen(pen);
static const QPointF points[6] = {
QPointF(300.0, 160.0),//Top Line
QPointF(220.0, 160.0),//
//QPointF(300.0, 180.0),
QPointF(195.0, 210.0),
QPointF(220.0, 260.0),//
QPointF(300.0, 260.0),//Bottom Line
QPointF(325.0, 210.0)
};
painter.drawPolygon(points, 6);
qDebug() << "Cnt=" << cnt;
cnt++;
QPainter painter1(this);
QPen pen1(Qt::green);
painter1.setPen(pen1);
QLinearGradient grad1(300, 160, 325, 260);
QBrush brush1(grad1);
grad1.setColorAt(1.0, Qt::white);
painter1.setBrush(brush1);
QFont font("Times", 12);
painter1.setFont(font);
QPoint point1 = QPoint( 240, 225);
painter1.drawText( point1, text_str );
}
and
NewWindow::NewWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::NewWindow)
{
ui->setupUi(this);
QString string = "Gello";
w1 = new MainWindow(string ,this);
w1->show();
}
Please guide me i am trying to resolve this since 1 day.
Is i have to call paintEvent() manually but i read at a place there is no need to call it manually.
Thanks.
Waiting for your reply.