Results 1 to 2 of 2

Thread: Changing the border of a QRubberBand

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

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Changing the border of a QRubberBand

    Seems like all you need to do is to change "m_offset" in the timeout slot by incrementing it with each timeout (mod( pattern length) so it cycles from 0 to pattern length). Otherwise it looks to me like you have interpreted the dash pattern and offset methods correctly.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.