Results 1 to 4 of 4

Thread: making a RubberBand for selecting an area

  1. #1
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default making a RubberBand for selecting an area

    Hi,

    I need to select an area with a RubberBand that returns QRectF::top, QRectF::bottom, QRectF::left, QRectF::right. For this I do this:

    Qt Code:
    1. QwtPlotZoomer* zoomer = new QwtPlotZoomer( canvas );
    2. zoomer->setRubberBandPen( QColor( Qt::red ) );
    3. zoomer->setTrackerPen( QColor( Qt::green ) );
    4. zoomer->setMousePattern( QwtEventPattern::MouseSelect2,
    5. Qt::RightButton, Qt::ControlModifier );
    6. zoomer->setMousePattern( QwtEventPattern::MouseSelect3,
    7. Qt::RightButton );
    To copy to clipboard, switch view to plain text mode 

    and by using zoomed (const QRectF &rect) signal, rect can be obtain.

    Qt Code:
    1. connect(zoomer, zoomed (QRectF), this, slot_pos(QRectF));
    2.  
    3. void MyClass::slot_pos(QRectF pos)
    4. {
    5. qDebug() << pos.top << pos.bottom << pos.left << pos.right;
    6. }
    To copy to clipboard, switch view to plain text mode 

    now I have this problem:
    Mouse LeftButton causes zooming. I want to to select an area with a RubberBand without zooming by for example LeftButton +ctrl.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: making a RubberBand for selecting an area

    QwtPlotZoomer - zooming = QwtPlotPicker;

    The keys or mouse actions being used for starting,moving and terminating the selection is customizable.

    Uwe

  3. #3
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: making a RubberBand for selecting an area

    Thanks Uwe, I used this and nothing happens and no RubberBand has been appeared:
    Qt Code:
    1. QwtPlotPicker* picker= new QwtPlotPicker( canvas );
    2.  
    3. picker->setRubberBandPen( QColor( Qt::red ) );
    4. picker->setTrackerPen( QColor( Qt::green ) );
    5. picker->setMousePattern( QwtEventPattern::MouseSelect2,
    6. Qt::RightButton, Qt::ControlModifier );
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: making a RubberBand for selecting an area

    This is your initial sequence to get something started:
    Qt Code:
    1. QwtPlotPicker* picker= new QwtPlotPicker( plot->canvas() );
    2. picker->setStateMachine( new QwtPickerDragRectMachine() );
    3. picker->setRubberBand( QwtPlotPicker::RectRubberBand );
    4. picker->setRubberBandPen( QColor( Qt::red ) );
    5. picker->setTrackerPen( QColor( Qt::green ) );
    6. picker->setTrackerMode( QwtPlotPicker::ActiveOnly );
    7.  
    8. connect( picker, SIGNAL( selected( const QRectF &rect ) ), ... );
    To copy to clipboard, switch view to plain text mode 
    Choose the type of state machine you like and check its docs, what type of event patterns are used by it. In case of the rectangle machines it is using QwtEventPattern::MouseSelect1 and QwtEventPattern::KeySelect1 - what means changing QwtEventPattern::MouseSelect2 ( like in your code snippet ) will have no effect.

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    Alex22 (13th July 2016)

Similar Threads

  1. RubberBand lines
    By vandanadk in forum Newbie
    Replies: 3
    Last Post: 5th April 2011, 18:44
  2. RubberBand Problem
    By zgulser in forum Qt Programming
    Replies: 10
    Last Post: 16th February 2009, 07:05
  3. Replies: 1
    Last Post: 29th November 2008, 12:37
  4. Drawing a Rubberband
    By daviddoria in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 14:32
  5. Rubberband zoom
    By sreedhar in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2006, 11:38

Tags for this Thread

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.