Results 1 to 2 of 2

Thread: Changing the border of a QRubberBand

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    5

    Default Changing the border of a QRubberBand

    Hello,

    In my program I draw rectangle rubberbands on a QGraphicsView with the mouse and I now I want to have the border of the rubber band have a marching ant kind of effect.
    The first thing I am trying to to is subclassing the QRubberband and re-implementing the paintEvent. And also set the effect using a QTimer.
    The QTimer is in my QGV class.

    I simply set the timer up there.
    Qt Code:
    1. ...
    2. m_timer = new QTimer(this);
    3. connect(m_timer, SIGNAL(timeout()), this, SLOT(updateBorder()));
    4. m_timer->start(400);
    5. ...
    6.  
    7. void WaveObject::updateBorder()
    8. {
    9. m_rubberBand->update(); //MyRubberBand object
    10. }
    To copy to clipboard, switch view to plain text mode 

    Then in my QRubberband subclass I am trying a few things:

    Qt Code:
    1. void MyRubberBand::paintEvent(QPaintEvent *event)
    2. {
    3. QPen pen;
    4. QVector<qreal> dashes;
    5. qreal space = 2;
    6. dashes << 1 << space << 3 << space << 9 << space
    7. << 2 << space << 2 << space;
    8. pen.setDashPattern(dashes);
    9. pen.setDashOffset(m_offset);
    10.  
    11. QStylePainter painter(this);
    12. initStyleOption(&option);
    13. painter.setPen(pen);
    14. painter.drawControl(QStyle::CE_RubberBand, option);
    15. }
    To copy to clipboard, switch view to plain text mode 

    This doesn't do anything yet, which si expected because I don't really understand very well how the offset and setting patterns work. Can someone point in the right direction ?? Any help much appreciated.
    Thanks!
    Last edited by Sergex; 31st July 2012 at 17:12.

Similar Threads

  1. Replies: 2
    Last Post: 21st March 2012, 14:30
  2. Replies: 4
    Last Post: 8th September 2011, 08:22
  3. Replies: 0
    Last Post: 14th January 2010, 06:48
  4. Replies: 2
    Last Post: 10th August 2009, 09:45
  5. Use of QRubberBand
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2009, 12:59

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.