PDA

View Full Version : MouseEvent and colors



arubagirl
15th April 2011, 09:39
Hello,

I'm just new in C++ and now we have in school very difficult lessons which we need to make.
Here's one i just don't get working. We have a picture with lines, the lines must change color when i press the left or right mousebutton.

rightnow i've the code



void Hoofdscherm::mousePressEvent(QMouseEvent *event)
{
Qt::MouseButtons pressed;
pressed = event->button();

if (pressed.button == Qt::LeftButton)
{penKleur = Qt::green;}
else
if (pressed.button ==Qt::RightButton)
{penKleur = Qt::yellow;}
}


it's not going to work. i know you can make it with switch but we didn't have that in school yet so it must be different.

high_flyer
15th April 2011, 10:24
Your code is not that bad.
Either change Qt::MouseButtons to Qt::MouseButton, or make sure you extract the mouse button you are looking from Qt::MouseButtons.
I assume your 'penKleur' is used in a paintEvent().
You can call update() at the end of the mouse event to cause new redering of the widget.

Man you are lucky to get to learn Qt in school....