Results 1 to 9 of 9

Thread: Mouse event problem

  1. #1
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Qt products
    Qt4

    Default Mouse event problem

    how can i get the coordinates feedback if i click the left button on my qgraphicscene.
    Qt Code:
    1. void MainWindow::mousePressEvent(QMouseEvent *event)
    2. {
    3. if(event->button() == Qt::LeftButton )
    4. {
    5. //im not sure what code i should put in here
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Mouse event problem


  3. #3
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Qt products
    Qt4

    Default Re: Mouse event problem

    im able to get the coordinates from the mainwindow, which mean (0,0) is at the top left of the mainwindow, how do i set (0,0) at the top left of my qgraphicsview?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Mouse event problem


  5. #5
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Qt products
    Qt4

    Default Re: Mouse event problem

    i cant get it, you have any source codes as reference ?? how about you tell me if i can enable mouse event only in my qgraphicsview?
    Last edited by cheyanne; 24th December 2011 at 14:27.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Mouse event problem

    Only because today it is Christmas eve! (normally it shouldn't be a problem for you, to write a small demo app, where you can play around.)
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Main : public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7. Main(QWidget *parent = 0) : QWidget(parent) {
    8. m_green = new QWidget(this);
    9. QPalette p = m_green->palette();
    10. p.setColor(QPalette::Window, Qt::green);
    11. m_green->setPalette(p);
    12. m_green->setAutoFillBackground(true);
    13. m_green->setMinimumSize(50, 50);
    14.  
    15. l->addWidget(m_green);
    16. l->setContentsMargins(100, 100, 100, 100);
    17. setLayout(l);
    18. }
    19. virtual ~Main() {}
    20. protected:
    21. void mousePressEvent(QMouseEvent *e) {
    22. qWarning() << Q_FUNC_INFO;
    23. qWarning() << " pos:" << e->pos();
    24. qWarning() << " gpos:" << e->globalPos();
    25. qWarning() << "child:"
    26. << m_green->mapFromParent(e->pos())
    27. << m_green->mapFromGlobal(e->globalPos())
    28. << m_green->mapFrom(this, e->pos());
    29. }
    30. private:
    31. QWidget *m_green;
    32. };
    33.  
    34.  
    35. int main(int argc, char *argv[])
    36. {
    37. QApplication a(argc, argv);
    38.  
    39. Main w;
    40. w.show();
    41.  
    42. return a.exec();
    43. }
    44.  
    45. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Qt products
    Qt4

    Default Re: Mouse event problem

    thanks how about mouseevent only in qgraphicsview? not anywhere else. Can this be done ?

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Mouse event problem

    yes, but you will find out yourself... By reading the documentation.

  9. #9
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Qt products
    Qt4

    Default Re: Mouse event problem

    Do I use mouse area?

Similar Threads

  1. Replies: 1
    Last Post: 3rd August 2011, 01:14
  2. QLabel mouse event problem
    By danics in forum Qt Programming
    Replies: 2
    Last Post: 11th March 2010, 13:38
  3. create mouse click event problem
    By yagabey in forum Qt Programming
    Replies: 6
    Last Post: 8th October 2009, 21:45
  4. problem in mouse event
    By bhogasena in forum Qt Programming
    Replies: 0
    Last Post: 28th January 2009, 12:58
  5. Mouse click event problem
    By impeteperry in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2007, 13:44

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.