Results 1 to 3 of 3

Thread: Keep pixels Highlighted wherever cursor moved after entering the widget.

  1. #1
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Keep pixels Highlighted wherever cursor moved after entering the widget.

    I want to highlight all the pixels where cursor moved after entering the widget and before leaving it.
    On reimplementing the paintEvent and using drawPoint, I am able to display the current cursor position. But I dont want old points to disappear. How do i keep all previous points also highlighted???
    I am not successful in using drawPath and drawPoints for this.

    Qt Code:
    1. Lines::Lines(QWidget *parent) :
    2. QWidget(parent),
    3. ui(new Ui::Lines)
    4. {
    5. ui->setupUi(this);
    6. }
    7.  
    8.  
    9. void Lines::paintEvent(QPaintEvent *e)
    10. {
    11. QPainter qp(this);
    12. drawLines(&qp);
    13. }
    14.  
    15.  
    16. void Lines::drawLines(QPainter *qp)
    17. {
    18. QPen pen2(Qt::red, 8, Qt::SolidLine);
    19. qp->setPen(pen2);
    20.  
    21. int x;
    22. int y;
    23.  
    24. QPoint p = QCursor::pos();
    25. x = p.x();
    26. y= p.y();
    27.  
    28. qp->drawPoint(p);
    29. this->update();
    30. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Keep pixels Highlighted wherever cursor moved after entering the widget.

    Why do you expect it to work? You are not doing anything to record the pixels that need to be drawn on each update. Exactly how you do that will depend on what else is drawn in the widget. See the Scribble Example in the docs for how you might approach this for a blank image.

    BTW, as the docs say:
    Note: Generally, you should refrain from calling update() or repaint() inside a paintEvent(). For example, calling update() or repaint() on children inside a paintevent() results in undefined behavior; the child may or may not get a paint event.

  3. #3
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Keep pixels Highlighted wherever cursor moved after entering the widget.

    I dont expect this to work. This is just the code to track current position of cursor.
    I am stuck with how to record so many pixels and how to pass them as parameters.
    and if i dont update, only the first cursor position is highlighted, after that nothing would happen.
    Last edited by learner_qt; 8th February 2013 at 07:36. Reason: updated contents

Similar Threads

  1. Replies: 0
    Last Post: 10th June 2010, 23:38
  2. Keep Cursor in a widget
    By TheClerk in forum Qt Programming
    Replies: 9
    Last Post: 6th February 2010, 18:24
  3. Restricting a widget from being moved
    By ArmanS in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2009, 15:48
  4. Replies: 4
    Last Post: 3rd March 2008, 22:15
  5. Real size in pixels of a widget
    By yosefm in forum Qt Programming
    Replies: 3
    Last Post: 27th October 2007, 16:01

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.