I would like to paint a QPolygon on my Window and be able to use it as a QPushbutton. Is there any way to do this? (most preferably without using QMousePressEvent to check the position of the mouse with the position of the polygon)
After the advice of Ton:
MainWindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
qv_point = {QPoint(10,20), QPoint(20,30), QPoint(50,30)};
ui->pushButton = new QPolygonPushButton(qv_point);
ui->setupUi(this);
ui->pushButton->update();
}
MainWindow::~MainWindow()
{
delete ui;
}
qpolygonpusbutton.cpp:
#include "qpolygonpushbutton.h"
QPolygonPushButton::QPolygonPushButton(QVector<QPoint> qv_points)
{
this->polygon << qv_points;
}
void QPolygonPushButton::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
painter.setViewport(e->rect());
painter.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.drawPolygon(this->polygon);
}