PDA

View Full Version : Painting Problem on Mac



shyam prasad
2nd February 2007, 09:39
hi Everybody .

I am using Qt 4.2 , on Mac OS

Please execute this code on Mac OS.

After button click setMask called .
when i want to do repainting ,
painting in side the widget is moving .


sample.cpp


myWidget::myWidget(QWidget *parent): QWidget(parent)
{
bRgnSet=false;
QPushButton *quit = new QPushButton("Click", this);
quit->setFont(QFont("Times", 18, QFont::Bold));
quit->setGeometry(75,75,30,30);
setGeometry(0, 0, 400, 400);
connect(quit, SIGNAL(clicked()), this, SLOT(ButtonPressed()));

m_ptArr1[0] = QPoint(50,50);
m_ptArr1[1] = QPoint(380,120);
m_ptArr1[2] = QPoint(280,350);
m_ptArr1[3] = QPoint(80,180);
m_ptArr1[4] = QPoint(50,50);

}

void myWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::blue);

painter.drawRect(100,100,200,200);
painter.drawEllipse(150,150,100,100);

if(bRgnSet)
{
painter.translate(50,50);
}

if(bRgnSet)
{
painter.drawEllipse(300,300,50,50);
painter.drawLine(0,0,400,400);
}

}

void myWidget::ButtonPressed()
{
//QRegion widgetRgn(54,39,200,200,QRegion::Ellipse);
bRgnSet = true;
QPolygon rlPolygon;
rlPolygon.setPoints(5, m_ptArr1[0].x(), m_ptArr1[0].y(), m_ptArr1[1].x(), m_ptArr1[1].y(),
m_ptArr1[2].x(), m_ptArr1[2].y(), m_ptArr1[3].x(), m_ptArr1[3].y(), m_ptArr1[4].x(), m_ptArr1[4].y(),
m_ptArr1[5].x(), m_ptArr1[5].y());
QRegion rlRegion(rlPolygon);
setMask( rlPolygon );
//setMask( widgetRgn );

}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
myWidget widget;

widget.show();
return app.exec();
}



sample.h




class myWidget: public QWidget
{
Q_OBJECT
public:
QPoint m_ptArr1[5];
bool bRgnSet;
myWidget(QWidget *parent = 0);
void paintEvent(QPaintEvent *);

public slots:
void ButtonPressed();
};


Add appropriate header files to sample .cpp & sample.h


Implement repaint after clicking the button .


Any body knows the reason pls revert me back .

Thankyou

Shyam Boga

wysota
2nd February 2007, 09:58
What do you mean that it is moving?