Results 1 to 2 of 2

Thread: MouseEvent and colors

  1. #1
    Join Date
    Apr 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default MouseEvent and colors

    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


    Qt Code:
    1. void Hoofdscherm::mousePressEvent(QMouseEvent *event)
    2. {
    3. Qt::MouseButtons pressed;
    4. pressed = event->button();
    5.  
    6. if (pressed.button == Qt::LeftButton)
    7. {penKleur = Qt::green;}
    8. else
    9. if (pressed.button ==Qt::RightButton)
    10. {penKleur = Qt::yellow;}
    11. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent and colors

    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....
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. mouseEvent with two mice
    By yun in forum Newbie
    Replies: 0
    Last Post: 6th May 2009, 10:25
  2. problem in mouseEvent
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 9th April 2009, 06:20
  3. MouseEvent on a line
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 25th March 2006, 08:52
  4. MouseEvent on QTextEdit
    By Sarma in forum Qt Programming
    Replies: 14
    Last Post: 10th March 2006, 09:49
  5. MouseEvent & QTextEdit
    By Sarma in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2006, 23:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.