View Full Version : Bordered Line/ Point or any closed Figure
SumitDhyani
2nd May 2017, 14:06
Hi,
As for many days I was trying to get a line or point or any closed figure which will have borders around it. By use of QPainter with specific QPen or QBrush it is drawing (using drawLine, drawpoint, drawPolyline etc) only single color figure.
Is there any way to get closed figure with border around line. 12453
Santosh Reddy
3rd May 2017, 04:33
Use QPainterPath
SumitDhyani
3rd May 2017, 05:48
Use QPainterPath
Actually I searched for possibility of doing this but could find any way, even with QPainterPath. Can you please tell me how to use QPainterPath for the same?
Santosh Reddy
3rd May 2017, 06:55
Not sure what exactly what you want to do, anyway here is an example to use QPainterPath.
class MyWidget : public QWidget
{
public:
explicit MyWidget(QWidget * parent = 0)
: QWidget(parent) { }
protected:
void paintEvent(QPaintEvent * event)
{
QPainter painter(this);
QPainterPath path;
const QRect rect = event->rect();
const QPoint center = rect.center();
const int height = rect.height() / 4;
const int width = rect.width() / 4;
path.moveTo(center);
path.moveTo(center.x() , center.y() - height);
path.lineTo(center.x() + width , center.y() - height);
path.lineTo(center.x() + width , center.y());
path.lineTo(center.x() + width , center.y() + height);
path.closeSubpath();
painter.setPen(QPen(QBrush(Qt::red), 5));
painter.drawPath(path);
painter.fillPath(path, QBrush(Qt::CrossPattern));
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.