Results 1 to 7 of 7

Thread: Using QTimer and mouseMoveEvent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Using QTimer and mouseMoveEvent

    Your highlight routine is called once every 500 ms and will do something if the last mouse move event over this widget recorded a position that precisely matches the position of one of your cardIconPlayer objects (whatever they are). That's a precise match on a single pixel position not an area: unlikely to occur, I think you'll agree.

    What type are the cardIconPlayer objects?
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  2. #2
    Join Date
    Sep 2013
    Posts
    20
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    7

    Default Re: Using QTimer and mouseMoveEvent

    cardIconPlayer is a QLabel and this is how I set up the icons using pixmap.

    Qt Code:
    1. void Canvas::setUpPlayerIcons(string *pString)
    2. {
    3. QPixmap qpx;
    4. QSize iconSize;
    5. string str;
    6.  
    7. for (int i = 0; i < MAXCARDS; i++)
    8. {
    9. shadow = new QGraphicsDropShadowEffect(this);
    10. shadow->setBlurRadius(10);
    11.  
    12. cardIconPlayer[i] = new QLabel(cardTable);
    13. str = pString[i];
    14. qpx = QPixmap(str.c_str());
    15. iconSize = qpx.size();
    16. iconSize.scale(190, 276, Qt::KeepAspectRatio);
    17. QPixmap scaledImage = qpx.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    18. cardIconPlayer[i]->setPixmap(scaledImage);
    19. cardIconPlayer[i]->move(20 + 60 * i, 350);
    20. cardIconPlayer[i]->setGraphicsEffect(shadow);
    21.  
    22. //playerPixmaps.push_back(scaledImage);
    23. }
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    Just to get this straight. Are you saying I should use QRect instead of QPoint.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Using QTimer and mouseMoveEvent

    I would be inclined to make the QLabels look after their own highlighting when the mouse is over them.

    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QVBoxLayout>
    4. #include <QLabel>
    5. #include <QPixmap>
    6. #include <QGraphicsDropShadowEffect>
    7.  
    8. class Label: public QLabel
    9. {
    10. Q_OBJECT
    11. public:
    12. Label(QWidget *p = 0): QLabel(p)
    13. {
    14. QPixmap pixmap(200, 200);
    15. pixmap.fill(QColor("mediumseagreen"));
    16. setPixmap(pixmap);
    17. setFrameStyle(QFrame::Box);
    18.  
    19. QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
    20. shadow->setBlurRadius(10);
    21. shadow->setColor(QColor("orchid"));
    22. setGraphicsEffect(shadow);
    23. }
    24. protected:
    25. void enterEvent(QEvent *event)
    26. {
    27. QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
    28. shadow->setBlurRadius(10);
    29. shadow->setColor(QColor("lightsalmon"));
    30. setGraphicsEffect(shadow);
    31. }
    32. void leaveEvent(QEvent *event)
    33. {
    34. QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
    35. shadow->setBlurRadius(10);
    36. shadow->setColor(QColor("orchid"));
    37. setGraphicsEffect(shadow);
    38. }
    39. };
    40.  
    41. class Widget: public QWidget
    42. {
    43. Q_OBJECT
    44. public:
    45. Widget(QWidget *p = 0): QWidget(p)
    46. {
    47. QVBoxLayout *layout = new QVBoxLayout(this);
    48. layout->addWidget(new Label);
    49. layout->addWidget(new Label);
    50. }
    51. };
    52.  
    53. int main(int argc, char **argv)
    54. {
    55. QApplication app(argc, argv);
    56. Widget w;
    57. w.show();
    58. return app.exec();
    59. }
    60. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to ChrisW67 for this useful post:

    LaTj (3rd December 2013)

  5. #4
    Join Date
    Sep 2013
    Posts
    20
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    7

    Default Re: Using QTimer and mouseMoveEvent

    Thank you very much, this was more than thankful. Sorry for the late reply

Similar Threads

  1. Replies: 1
    Last Post: 25th October 2012, 19:47
  2. Replies: 15
    Last Post: 4th August 2012, 19:11
  3. mouseMoveEvent
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2009, 09:04
  4. mouseMoveEvent receiving zero's
    By JohnTh in forum Newbie
    Replies: 2
    Last Post: 11th September 2009, 17:31
  5. About the mouseMoveEvent()
    By bingoking in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2008, 11:56

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
  •  
Qt is a trademark of The Qt Company.