Not sure what exactly what you want to do, anyway here is an example to use QPainterPath.
{
public:
explicit MyWidget
(QWidget * parent
= 0)
protected:
{
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.drawPath(path);
painter.
fillPath(path,
QBrush(Qt
::CrossPattern));
}
};
int main(int argc, char *argv[])
{
MyWidget widget;
widget.show();
return app.exec();
}
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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks