{
// vtempButtonPushed has 3 possible states (see paintEvent() above). If mouse button is clicked, move to the next state. After the state 3, draw nothing (vtempButtonPushed == 4) and move back to state 1 with the next click
if (vtempButtonPushed <=3)
{
vtempButtonPushed += 1;
}
else
{
vtempButtonPushed = 1;
}
update();
}
void OutputWindow::mousePressEvent(QMouseEvent*)
{
// vtempButtonPushed has 3 possible states (see paintEvent() above). If mouse button is clicked, move to the next state. After the state 3, draw nothing (vtempButtonPushed == 4) and move back to state 1 with the next click
if (vtempButtonPushed <=3)
{
vtempButtonPushed += 1;
}
else
{
vtempButtonPushed = 1;
}
update();
}
To copy to clipboard, switch view to plain text mode
Checking the current state and choose the painting accordingly:
{
// vtempButtonPushed == 0 do nothing / 1 blue line / 2 red line / 3 green line
if (vtempButtonPushed == 1)
{
QPen pen
(Qt
::blue,
10, Qt
::SolidLine, Qt
::SquareCap, Qt
::BevelJoin);
painter.setPen(pen);
painter.drawLine(0, 0, 800, 800);
}
else if (vtempButtonPushed == 2)
{
QPen pen
(Qt
::red,
10, Qt
::SolidLine, Qt
::SquareCap, Qt
::BevelJoin);
painter.setPen(pen);
painter.drawLine(0, 0, 800, 800);
}
else if (vtempButtonPushed == 3)
{
QPen pen
(Qt
::green,
10, Qt
::SolidLine, Qt
::SquareCap, Qt
::BevelJoin);
painter.setPen(pen);
painter.drawLine(0, 0, 800, 800);
}
}
void OutputWindow::paintEvent(QPaintEvent*)
{
// vtempButtonPushed == 0 do nothing / 1 blue line / 2 red line / 3 green line
if (vtempButtonPushed == 1)
{
QPainter painter(this);
QPen pen(Qt::blue, 10, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
painter.setPen(pen);
painter.drawLine(0, 0, 800, 800);
}
else if (vtempButtonPushed == 2)
{
QPainter painter(this);
QPen pen(Qt::red, 10, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
painter.setPen(pen);
painter.drawLine(0, 0, 800, 800);
}
else if (vtempButtonPushed == 3)
{
QPainter painter(this);
QPen pen(Qt::green, 10, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
painter.setPen(pen);
painter.drawLine(0, 0, 800, 800);
}
}
To copy to clipboard, switch view to plain text mode
This works for my outputWindow Widgets individually (see picture attached). Although I can control the individual behaviour of each Widget by using
if (vtempButtonPushed == 1 && (this->objectName() != "outputWindowA"))
if (vtempButtonPushed == 1 && (this->objectName() != "outputWindowA"))
To copy to clipboard, switch view to plain text mode
Bookmarks