Results 1 to 2 of 2

Thread: Clicking on QwtPlot

  1. #1
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1

    Default Clicking on QwtPlot

    I'm adapting the Qwt "realtime" example into a new application, and I would like to know when a user clicks on a plot in the main window. I will have multiple plots, and it's important to know which plot is clicked on. So far I have:

    Qt Code:
    1. // Add plots and connect their signals
    2. // The "clicked()" signal is not actually doing anything
    3. void MainWindow::add_plots()
    4. {
    5. for (int i=0; i<m_num_rows; i++) {
    6. for (int j=0; j<m_num_cols; j++) {
    7. int index = i*m_num_cols+j;
    8. m_plots[index] = new QRealtimePlot(m_plots_frame);
    9. m_plots_layout->addWidget(m_plots[index], i, j);
    10. m_plots[index]->setMargin(4);
    11. connect(d_clearAction, SIGNAL(triggered()), m_plots[index], SLOT(clear()));
    12. connect(m_plots[index], SIGNAL(running(bool)), this, SLOT(showRunning(bool)));
    13. connect(m_plots[index], SIGNAL(clicked()), m_signal_mapper, SLOT(map()));
    14.  
    15. m_signal_mapper->setMapping(m_plots[index], index);
    16. }
    17. }
    18. connect(m_signal_mapper, SIGNAL(mapped(int)), this, SLOT(slot_plot_clicked(int)));
    19. }
    To copy to clipboard, switch view to plain text mode 

    QRealtimePlot is basically IncrementalPlot from the "realtime" example, including the Zoomer / ScrollZoomer classes. m_plot_layout is a QGridLayout whose parent is a frame in the MainWindow. d_clearAction is the "Clear" button on the toolbar, also straight out of the example.

    So, here are my questions:

    1) Is there a better way of doing this?
    2) If not, what signal (if any) can I connect to m_signal_mapper to make this work?
    3) I discovered that the clicked signal wasn't working by connecting to a slot that added an item to a list. This is an awful way of debugging. How do I do debugging output? Printing to stdout/stderr is not working (because of the QMainWindow class?)

    Edit: I'm using Qt 4.7 and Qwt 6.0.0-rc5, and I'm very new to both.

    Thanks,
    Tom

  2. #2
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1

    Talking Re: Clicking on QwtPlot

    Solved, primarily by not using qwt 6.0.0-rc5.

    I used the exact same code that I hoped would work in my original post, switched to using qwt-5.2.1, and added the following to my QRealtimePlot constructor:

    Qt Code:
    1. m_picker = new QwtPlotPicker(canvas());
    2. m_picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);
    3. connect(m_picker, SIGNAL(selected(const QwtDoublePoint &)), this, SIGNAL(clicked()));
    4.  
    5. // Drag selection to not interfere with clicking on plot
    6. zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection);
    To copy to clipboard, switch view to plain text mode 

    zoomer is the Zoomer class bundled with the realtime_plot example, and clicked() is a signal I added to the header file.

    But still, how should this be done in Qwt 6?

Similar Threads

  1. Replies: 2
    Last Post: 3rd April 2011, 13:48
  2. Double Clicking Pro File
    By BalaQT in forum Installation and Deployment
    Replies: 2
    Last Post: 18th November 2009, 06:23
  3. get html tag by clicking (webkit)
    By billconan in forum Qt Programming
    Replies: 0
    Last Post: 23rd June 2009, 23:07
  4. Replies: 6
    Last Post: 14th May 2009, 13:02
  5. Clicking Whitespace in a table
    By shooogun in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2008, 07:29

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.