Results 1 to 5 of 5

Thread: different selection modes of QwtPlotPicker

  1. #1
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question different selection modes of QwtPlotPicker

    Hello,

    I'm using the QwtPlotPicker and I'm wondering whether it is possible to have both Point- and RectSelection modes simultanously. So that if I click one time on a QwtPlotItem/QwtPlotMarker then it is selected, but if I drag a rectangle to select more than one item, then all items within the dragged rectangle shall be selected.
    Is this possible to do? If yes, tell me please how to achieve it.

    Thank you

    regards

  2. #2
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: different selection modes of QwtPlotPicker

    I expected that the QwtPlotPicker can handle both the PointSelection and RectSeletion modes, so that if I click one time on an item then the SIGNAL selected(const QwtDoublePoint &pos) is called and if drag a rectangle around several items then the SIGNAL selected(const QwtDoubleRect &rect) would be called. Obviosly my expectations are not right, because I can only use one of this two selection modes. How shall be the QwtPlotPicker parameterized to fulfill my expectation? The following code does not do the right thing:

    Qt Code:
    1. picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
    2. QwtPicker::PointSelection | QwtPicker::RectSelection | QwtPicker::DragSelection,
    3. QwtPlotPicker::RectRubberBand, QwtPicker::AlwaysOn,
    4. this->canvas());
    5.  
    6. // connect the signals coming from QwtPlotPicker with the member functions
    7. connect( picker, SIGNAL(moved(const QwtDoublePoint& ) ),
    8. this, SLOT(cursorMoved( const QwtDoublePoint& ) ) );
    9.  
    10. connect( picker, SIGNAL(selected( const QwtDoublePoint& ) ),
    11. this, SLOT(cursorSelected( const QwtDoublePoint& ) ) );
    12.  
    13. connect( picker, SIGNAL(selected (const QwtDoubleRect &) ),
    14. this, SLOT(RectangleSelected( const QwtDoubleRect& ) ) );
    To copy to clipboard, switch view to plain text mode 

    Or is here another logical problem? Help me please.

    Thank you

  3. #3
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: different selection modes of QwtPlotPicker

    I'm using now the QwtPlotPicker in RectSelection, DragSelection mode:
    Qt Code:
    1. // create QwtPlotPicker to allow user moving the points on the plot
    2.  
    3. picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
    4. QwtPicker::RectSelection | QwtPicker::DragSelection,
    5. QwtPlotPicker::RectRubberBand, QwtPicker::AlwaysOn,
    6. this->canvas());
    7.  
    8. // connect the signals coming from QwtPlotPicker with the member functions
    9. connect( picker, SIGNAL(moved(const QwtDoublePoint& ) ),
    10. this, SLOT(cursorMoved( const QwtDoublePoint& ) ) );
    11.  
    12. connect( picker, SIGNAL(selected (const QwtDoubleRect &) ),
    13. this, SLOT(RectangleSelected( const QwtDoubleRect& ) ) );
    To copy to clipboard, switch view to plain text mode 

    But it has unwished behaviour, if I drag the selected point, because during the dragging a selection rectangle is also painted. I would like to avoid it and just move the items, without drawing simulataneously the selection rectangle. It looks very strange. How can I achieve it? I tried to set another rubber band (NoRubberBand), after the selection, but how to reverse it, when the drag event is over?

    Another idea: perhaps it is possible to set different mousepatterns for different actions? For example selection with left mouse and dragging with right mouse? Can the QwtPlotpicker interpret it?

    another question: if I drag only one item, then in "cursorMoved" function I just set the mouseposition to the item's position and it works fine. If I select several items and want to drag them, then they get all the mouse position and appears at the same place. How can I implement such movement that the selected items only moves relatively to mouse direction and movement? Can you provide me a code snippet of it? I thought about storing the initial mouse click position and calculate the difference relatively to this initial point, but the "cursorMoved" function is called frequently while dragging so that this varaible would be overridden...

    my code:
    Qt Code:
    1. // this function provides the ability to select several items on the plot by dragging a rectangle around them
    2. void Plot::RectangleSelected( const QwtDoubleRect& rect){
    3. std::cout << "in Plot::RectangleSelected" << std::endl;
    4. //============= clear the list with selected items, before start new selection
    5. if(!selected_Points.empty()){
    6. while(!selected_Points.empty()){
    7. QwtPlotMarker *tempMark = selected_Points.back();
    8. const QwtSymbol symbol = tempMark->symbol();
    9. QwtSymbol newSymbol = symbol;
    10. newSymbol.setBrush(symbol.brush().color().light(150)); // turn back the highlighten symbol
    11. tempMark->setSymbol(newSymbol);
    12. selected_Points.pop_back(); // delete the selected items from the list
    13. }
    14. }
    15. //============= end of clear the list
    16.  
    17. const QwtPlotItemList& List = itemList(); // get all items from the plot
    18. QwtPlotItemIterator Iter = List.begin();
    19.  
    20. // get the two vertice of the selection rectangle
    21. QwtDoublePoint tl = rect.topLeft();
    22. QwtDoublePoint br = rect.bottomRight();
    23. std::cout << "recOfClick(x,y,width, height) =" << rect.x()<<", " << rect.y() << ", " << rect.width()<< ", "<<rect.height()<< std::endl;
    24. double TRtlX = this->transform(picker->xAxis(),tl.x()); // transform the rectangles coordinates to plot's coordinates
    25. double TRtlY = this->transform(picker->yAxis(),tl.y());
    26. double TRbrX = this->transform(picker->xAxis(),br.x());
    27. double TRbrY= this->transform(picker->yAxis(),br.y());
    28. QwtDoubleRect *trRect= new QwtDoubleRect(QRect(QPoint(TRtlX,TRtlY),QPoint(TRbrX,TRbrY))); // build a rectangle with the new coordinates
    29. std::cout << "recOfClick(x,y,width, height) =" << trRect->x()<<", " << trRect->y() << ", " << trRect->width()<< ", "<<trRect->height()<< std::endl;
    30. if( trRect->width()<5 && trRect->height()<5){ // if it was just a click and not drugged rectangle, then...
    31. trRect->setHeight(20); // ...generate a rectangle around the click's position
    32. trRect->setWidth(20);
    33.  
    34. }
    35.  
    36. while(Iter != List.end()) // and iterate through them...
    37. {
    38. if((*Iter)->rtti() == QwtPlotItem::Rtti_PlotMarker){ // ... until you find the item from class QwtPLotMarker
    39. QwtPlotMarker *mark = ((QwtPlotMarker*)(*Iter));
    40. double x = this->transform(mark->xAxis(),mark->xValue()); // transform the item's coordinates to plot's coordinates
    41. double y = this->transform(mark->yAxis(),mark->yValue());
    42. std::cout << "mark.xValue()=" << mark->xValue() << ", mark.yValue()=" << mark->yValue()<< std::endl;
    43. std::cout << "transformed mark coord = " << x << ", " << y<< std::endl;
    44. QwtDoublePoint trPoint = QwtDoublePoint(x,y); // create a point consisting of transformed coordinates
    45.  
    46.  
    47. if(trRect->contains(trPoint)){ // if click's rectangle includes the QwtPlotMarker, then...
    48. std::cout << "MATCH" << std::endl;
    49.  
    50. //selectedPoint = mark; // ... save the pointer to this item into variable "selectedPoint"
    51. std::cout << "selectedPoint = " << mark << std::endl;
    52. const QwtSymbol symbol = mark->symbol();
    53. QwtSymbol newSymbol = symbol;
    54. newSymbol.setBrush(symbol.brush().color().dark(150)); // highlighten the selected item by darken its color
    55. mark->setSymbol(newSymbol);
    56. selected_Points.push_back(mark);
    57. }
    58.  
    59. }
    60. Iter++;
    61. }
    62. replot();
    63. std::cout << "selected_Points.size()= " << selected_Points.size() << std::endl;
    64. }
    65. //##################################################################
    66. // this function provides the ability to move items on the plot
    67. void Plot::cursorMoved( const QwtDoublePoint& Point){
    68.  
    69. std::cout << "in Plot::cursorMoved " << std::endl;
    70. std::cout << "Point.x()= " << Point.x() <<"Point.y()= " << Point.y() << std::endl;
    71. if(!selected_Points.empty()){ //if the list with selected items is not empty, then...
    72. for(unsigned i=0; i< selected_Points.size(); ++i) {
    73. std::cout << "loop " << i << std::endl;
    74. selected_Points[i]->setValue(Point); // set the new coordinates to the moved item
    75. }
    76. this->replot(); // replot the plot widget after the selected point was moved
    77. }
    78. replot();
    79. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: different selection modes of QwtPlotPicker

    So, I have managed to avoid drawing the selection rectangle while dragging objects by switching between NoRubberBand and RectRubberBand here:

    Qt Code:
    1. void Plot::cursorMoved( const QwtDoublePoint& Point){
    2.  
    3. std::cout << "in Plot::cursorMoved " << std::endl;
    4. std::cout << "Point.x()= " << Point.x() <<"Point.y()= " << Point.y() << std::endl;
    5. if(!selected_Points.empty()){ //if the list with selected items is not empty, then...
    6. for(int i=0; i< selected_Points.size(); ++i) {
    7. picker->setRubberBand(QwtPicker::NoRubberBand);
    8. double delta_x = Point.x() - clickpos->x(); // calculate the x difference
    9. double delta_y = Point.y() - clickpos->y(); // calculate the y difference
    10. selected_Points[i]->setValue(selected_Points[i]->xValue() + delta_x, selected_Points[i]->yValue() + delta_y); // set the new coordinates to the moved item
    11. int index = (selected_Points[i]->title().text().toInt()); // transform from string to integer
    12. std::cout << "index = " << index<< std::endl;
    13. //mainFrame *mf = dynamic_cast<mainFrame*>(parentWidget());
    14. _mf->updateChromosome( selected_Points[i]->value(),index); // update the individuals with new values
    15. }
    16. this->replot(); // replot the plot widget after the selected point was moved
    17. }
    18. else{
    19. picker->setRubberBand(QwtPicker::RectRubberBand); // switch the RubberBand
    20. }
    21. clickpos = new QwtDoublePoint(Point); // update the reference point
    22. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: different selection modes of QwtPlotPicker

    Hello again

    I would like to differentiate between right and left mouse click while using QwtPlotPicker, so that the left mouse click do one action and the right click do another action (push back items in different vectors). How can I do it with QwtPlotPicker?

    best regards,

    Vitali

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 08:52
  2. Replies: 1
    Last Post: 19th November 2009, 00:21
  3. Custom selection actions in QTreeView
    By iraytrace in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2009, 21:51
  4. QListWidget's selection issues
    By mirni in forum Qwt
    Replies: 0
    Last Post: 5th November 2009, 21:08
  5. Save & Restore a selection in QTreeWidget
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 20:54

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.