Unsolved How to draw rounded live using QT
-
How can I design rounded line like this image.I need to design a rounded line when the button click.
void MainWindow::on_btnCreateRoundedLine_clicked() { }
-
Possibly as part of an ellipse
-
@koahnig Can you provide me sample code please
-
@CorD-SaC
Can you provide at little bit more information ?
Are you using QGraphicsView or QPainter ?
Where do you want to draw it ?
You cannot just paint in on_btnCreateRoundedLine_clicked
as all painting must be done in paintEvent function.
You could paint on a pixmap and use a QLabel to display it.Also what you are showing is not really a line with round edge but
more of a spline type.A very fast way would be to use drawing program like inkscape and simply load
it as a SVG image into a QLabel.
But it all really depends on what you are trying to do.
-
@mrjj I tried it like this problem solved.now I need to change the color of this shape when I select color from color dialog or another way,and also I need to rotate this Item.how can I do this?
This is my code.
void Widget::on_pushButton_clicked() { QPainterPath path; path.moveTo(10, 20); path.lineTo(10, 40); path.arcTo(QRectF(10, 20, 40, 40), 180, 180); path.moveTo(50, 40); path.lineTo(50, 20); QPen redPen(Qt::red); redPen.setWidth(2); QGraphicsPathItem* item = ui->graphicsView->scene()->addPath(path, redPen); /* QGraphicsPathItem* item = new QGraphicsPathItem(path); item->setPen(redPen); */ item->setFlag(QGraphicsItem::ItemIsMovable, true); item->setFlag(QGraphicsItem::ItemIsSelectable,true); }
-
- now I need to change the color of this shape
You can just do it
http://doc.qt.io/qt-5/qabstractgraphicsshapeitem.html#setPen -
@mrjj said in How to draw rounded live using QT:
can just do it
I solved rotate item problem. now I need to change color of this item.according to your answer I already use setPen method. But how can I change the color of this Item when I select color from color dialog.
-
How about this method setColor?
-
@koahnig Can You give some sample code.How can I pick color from QColorDialog and assign that color to this curve shape
-
There is this example in the document database