Results 1 to 10 of 10

Thread: QRubberBand class to draw a line

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default QRubberBand class to draw a line

    Hi how to use QRubberBand class to draw a line. According to docs, we can either draw a rectangle or a line. I'm able to draw a rectangle but not a line. Here is the sample code I have tried

    Qt Code:
    1. Myline::Myline( QWidget *parent, Qt::WFlags flags)
    2. : QWidget(parent, flags){
    3. RBand = 0;
    4. }
    5.  
    6. void Myline::mousePressEvent(QMouseEvent *event){
    7. first_pt = event->pos();
    8. last_pt = event->pos();
    9. if (!RBand)
    10. RBand = new QRubberBand(QRubberBand::Line, this);
    11. RBand->setGeometry(QRect(first_pt, last_pt));
    12. RBand->show();
    13. }
    14.  
    15. void Myline::mouseMoveEvent(QMouseEvent *event) {
    16. last_pt = event->pos();
    17. RBand->setGeometry(QRect(first_pt, last_pt));
    18. }
    19.  
    20. void Myline::mouseReleaseEvent(QMouseEvent *event) {
    21. last_pt = event->pos();
    22. RBand->hide();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Last edited by vermarajeev; 2nd April 2007 at 14:23.

Similar Threads

  1. QTextStream : Remove a Line?
    By kaydknight in forum Qt Programming
    Replies: 7
    Last Post: 31st January 2011, 18:15
  2. Draw rubberband line
    By Pang in forum Qt Programming
    Replies: 4
    Last Post: 13th July 2007, 23:09
  3. Find and line endings
    By mikeh in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2006, 10:16
  4. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  5. QListWidget-problem
    By Sarma in forum Qt Programming
    Replies: 7
    Last Post: 7th April 2006, 18:49

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.