Results 1 to 10 of 10

Thread: Get QRect of a widget using mouseevent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get QRect of a widget using mouseevent

    Wont QRubberBandbe of some use to you

  2. The following user says thank you to aamer4yu for this useful post:

    arpspatel (8th March 2010)

  3. #2
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get QRect of a widget using mouseevent

    You got the idea,

    Call update() in void theGui::mouseMoveEvent(QMouseEvent *event), not in theGui::drawRect(QPoint _s, QPoint, _e) (rename it drawRectSelection(QPoint _s, QPoint, _e) to avoid confusion QPainter:rawRect(etc...)) .
    No need to calll drawRect(startPoint,event->pos()) in void theGui::mouseMoveEvent(QMouseEvent *event);
    Use your flag in theGui:aintEvent(QPaintEvent *event) and do the painting of the selection rectangle in this function only.


    Or you can use QRubberBand as suggested...

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

    arpspatel (8th March 2010)

  5. #3
    Join Date
    Apr 2008
    Posts
    35
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Get QRect of a widget using mouseevent

    Qt Code:
    1. void theGui::mousePressEvent(QMouseEvent* event) {
    2. if (!rubberband)
    3. rubberband = new QRubberBand(QRubberBand::Rectangle, this);
    4. startPoint = event->pos();
    5. rubberband->setGeometry(QRect(startPoint,QSize()));
    6. rubberband->show();
    7. rubberBandActive = true;
    8. }
    9.  
    10.  
    11. void theGui::mouseMoveEvent(QMouseEvent* event) {
    12. if(rubberBandActive){
    13. rubberband->setGeometry(QRect(startPoint,event->pos()).normalized());
    14. }
    15. }
    16.  
    17. void theGui::mouseReleaseEvent(QMouseEvent* event) {
    18. if(rubberBandActive){
    19. endPoint = event->pos();
    20. rubberBandActive = false;
    21. rubberband->hide();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Thanks Guys... I tried the QRubberBand and it worked very well and on first try.. there is also an example in qt doc. I didnt even know there was a class like QRubberBand, so I have posted the code here just in case some one needs it.....
    Last edited by arpspatel; 8th March 2010 at 22:01.

  6. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get QRect of a widget using mouseevent

    I tried the QRubberBand and it worked very well and on first try.. there is also an example in qt doc. I didnt even know there was a class like QRubberBand
    Thats cuteness of Cute(Qt) ! You think, and its probable its there !

Similar Threads

  1. difference of QRect and QRectF
    By gbmtoday in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 22:52
  2. Pass mouseEvent to sibling widget?
    By nish in forum Qt Programming
    Replies: 5
    Last Post: 1st September 2009, 13:00
  3. Replies: 11
    Last Post: 17th January 2009, 09:06
  4. Move QCompleter on QRect x,y
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 10:33
  5. Replies: 1
    Last Post: 14th April 2007, 13:42

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.