Results 1 to 5 of 5

Thread: how to catch qMouseEvent

  1. #1
    Join Date
    Jul 2010
    Posts
    17
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default how to catch qMouseEvent

    Hi, i'm a newbie in QT, and i'm working in a proyect with it. now i need to get a simple MouseEvent but i don't get it.
    There is a class called ListaMensajes where QScrollArea is placed. Inside i can load PanelTx objects.
    The idea is to select the PanelTx object by clicking over each one.

    Qt Code:
    1. protected:
    2. void clickPanelTxEvent(QMouseEvent *e);
    3.  
    4. private:
    5. Ui::PanelTxClass ui;
    To copy to clipboard, switch view to plain text mode 

    and the definition ..
    Qt Code:
    1. PanelTx::PanelTx (CArincMsgData *msg, ListaMensajes &listaMensajes, QWidget *parent)
    2. : QWidget(parent), m_cListaMensajes (listaMensajes), m_pMessage (msg)
    3. {
    4. ui.setupUi(this);
    5.  
    6. m_pDialogPropiedades = 0;
    7.  
    8. loadValues ();
    9.  
    10. colorPanelTx(m_pMessage->isEnabledTx ()); //poner color activo-desactivo
    11. }
    12.  
    13. PanelTx::~PanelTx()
    14. {
    15.  
    16. }
    17. .............
    18.  
    19. void PanelTx::clickPanelTxEvent(QMouseEvent *e)
    20. {
    21.  
    22. if (e->button() == Qt::LeftButton)
    23. {
    24.  
    25. //this line is just to check it works
    26. this->setPalette(QPalette(Qt::white));
    27.  
    28. }
    29. else if (e->button() == Qt::RightButton)
    30. {
    31. ......
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    the line:
    this->setPalette(QPalette(Qt::white));
    works perfectly with this widget cause im using it in other parts, but i can't get the handler work for the QMouseEvents

    could anybody help me?
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to catch qMouseEvent

    Are you familiar with c++ and object oriented programming?

    You should re-implement the mouse events.

    Example:
    Qt Code:
    1. void MyClass::mousePressEvent ( QMouseEvent * event )
    2. {
    3. //Do something with the event, accept it, and/or pass it to qwidget
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2010
    Posts
    17
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to catch qMouseEvent

    thanks for the inconveniences, i have solved it with a eventFilter. I just wanted to manage the click over some panels, and finally i got it.
    i have begun 2 weeks ago with c++ and this project, but is still going on.
    thanks anyway

  4. #4
    Join Date
    May 2012
    Location
    India
    Posts
    51
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: how to catch qMouseEvent

    how mousePressEvent () will get called ????
    shall i have to call it manually ??

  5. #5
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to catch qMouseEvent

    Nope....

    include QMouseEvent header file.

    Then, override virtual function i.e.;
    Qt Code:
    1. void mousePressEvent(QMouseEvent *);
    To copy to clipboard, switch view to plain text mode 

    Then after that, define it in your cpp file. you dont have to call the function as it will call automatically.
    Use documentation.

Similar Threads

  1. how to catch qMouseEvent
    By pakine in forum Newbie
    Replies: 0
    Last Post: 5th July 2010, 17:16
  2. QMouseEvent
    By shenakan in forum Newbie
    Replies: 1
    Last Post: 20th August 2009, 14:53
  3. help needed in QMouseEvent
    By aj2903 in forum Qt Programming
    Replies: 21
    Last Post: 14th February 2009, 11:15
  4. qmouseEvent handling
    By nass in forum Qt Tools
    Replies: 9
    Last Post: 13th October 2006, 08:55
  5. QToolBox and QMouseEvent
    By mickey in forum Qt Programming
    Replies: 6
    Last Post: 1st February 2006, 11:57

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.