PDA

View Full Version : QPainterPath and moveTo problem



allting
15th May 2010, 08:12
Hi there.
I want to draw bezier with QPainterPath.
but moveTo() method draws one pixel line like attached image.

my code here.



QPoint s1, s2, e1, e2, cp11, cp12, cp21, cp22;

...

QPainterPath path;
path.moveTo(s2);
path.lineTo(s1);
path.cubicTo(cp11, cp12, e1);
path.lineTo(e2);

path.moveTo(s2); /// this line draws one pixel line...
path.cubicTo(cp21, cp22, e2);

pPainter_->setPen(Qt::NoPen);
pPainter_->fillPath(path, QBrush(QColor(aFillColor.r, aFillColor.b, aFillColor.g)));


How can i remove one pixel line on the bezier?

thanks

allting
15th May 2010, 13:45
I have to write a sample.:(



#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QgraphicsItem>
#include <QGraphicsTextItem>
#include <QPainter>

class MyWidget : public QWidget
{
protected:
void paintEvent ( QPaintEvent * event )
{
QPainter painter(this);

drawBeizer(painter, 0);
drawBeizer(painter, 1);
}

void drawBeizer(QPainter& painter, int i){

QPoint s1, s2, e1, e2, cp11, cp12, cp21, cp22;

if(0 == i){
s1 = QPoint(384,341); cp11 = QPoint(336,230); cp12 = QPoint(376,116); e1 = QPoint(220,92) ;
s2 = QPoint(400,330); cp21 = QPoint(352,230); cp22 = QPoint(392,116); e2 = QPoint(220,86) ;
}else{
s1 = QPoint(384,328); cp11 = QPoint(432,251); cp12 = QPoint(392,172); e1 = QPoint(564,149);
s2 = QPoint(400,343); cp21 = QPoint(448,251); cp22 = QPoint(408,172); e2 = QPoint(564,155);
}

QPainterPath path;
path.moveTo(s2);
path.lineTo(s1);
path.cubicTo(cp11, cp12, e1);
path.lineTo(e2);

path.moveTo(s2);
path.cubicTo(cp21, cp22, e2);

painter.setPen(Qt::NoPen);
painter.fillPath(path, QBrush(QColor(255, 90, 90)));
}

};


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

MyWidget view;
view.show();

return app.exec();
}


it wroks fine.
I still can not find the problem.:confused:

tbscope
15th May 2010, 14:34
it wroks fine.

Do you mean you still see the line or not?
Because the example you posted works fine for me, I do not see straight lines, only two pink beziers

allting
15th May 2010, 16:02
Sample works fine.
but, my real program still has problem.
I can't find why it does not work.