Results 1 to 6 of 6

Thread: How to set limits on a standalone QwtScaleWidget?

  1. #1
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default How to set limits on a standalone QwtScaleWidget?

    I'm trying to have a QwtScaleWidget that isn't associated with any specific plot, so I've instantiated one, put it in my layout and it shows up, so far so good. However, I can't seem to figure out how to manually set the limits on it! I've got the data I need in a vector, so it seems like it should be as simple as calling something like
    Qt Code:
    1. scaleWidget->setLimits(vec.first(), vec.last())
    To copy to clipboard, switch view to plain text mode 
    but there doesn't seem to be any function like that. I'm sure I'm missing something obvious...

    Longer explanation of what I'm trying to do if it helps: I've got a plot container widget that holds multiple plots, all vertically aligned in a vertical scroll area. All the plots share a common x-axis time scale, but the y-axes can vary wildly. So to save vertical pixels, I'd like to display a single scale widget OUTSIDE of the scroll area, and then hide all the x-axis scale widgets of each plot. So the scale widget I'm trying to create isn't associated with any one plot, but as the data comes in (this is a real-time data stream), I just need to continously update the limits of the scale widget to match the underlying data.

    Feel free to offer other suggestions if QwtScaleWidget isn't the correct thing to use, but it seem like it is, I'm just missing how to set the values of it.
    Last edited by SeanM; 19th August 2014 at 17:04. Reason: More descriptive title

  2. #2
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to set limits on a standalone QwtScaleWidget?

    I can't seem to figure out how to manually set the limits on it!
    I would try...
    Qt Code:
    1. QwtScaleDiv scaleDiv (lowerBound, upperBound);
    2. scaleWidget->setScaleDiv (scaleDiv ) ;
    To copy to clipboard, switch view to plain text mode 
    or, depending on how far along you are...
    Qt Code:
    1. QwtScaleDraw * scaleDraw = new QwtScaleDraw;
    2. QwtScaleDiv scaleDiv (lowerBound, upperBound);
    3. scaleDraw->setScaleDiv(scaleDiv);
    4. scaleWidget->setScaleDraw (scaleDraw );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set limits on a standalone QwtScaleWidget?

    Thanks for the reply. I thought I had tried that between my original post and your response, but it doesn't seem to have any effect? I'm trying to put together a minimal example right now...

    It looks like you need to use a QwtScaleEngine to produce a proper QwtScaleDiv object, unless I'm still missing something obvious. Here's my code:
    mainwindow.h
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8.  
    9. public slots:
    10. void updateScale();
    11.  
    12. private:
    13. Ui::MainWindow *ui;
    14. QTimer* scaleUpdateTimer;
    15. QwtScaleWidget* scaleWidget;
    16. double limit;
    17. QVBoxLayout* vbox;
    18. QCheckBox* useScaleEngine;
    19. };
    To copy to clipboard, switch view to plain text mode 
    mainwindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. limit = 0;
    7.  
    8. vbox = new QVBoxLayout(this);
    9. useScaleEngine = new QCheckBox("Use Scale Engine",this);
    10. scaleUpdateTimer = new QTimer(this);
    11. scaleWidget = new QwtScaleWidget(this);
    12.  
    13. vbox->addWidget(useScaleEngine);
    14. vbox->addWidget(scaleWidget);
    15. centralWidget()->setLayout(vbox);
    16.  
    17. useScaleEngine->setChecked(true);
    18.  
    19. scaleWidget->setAlignment(QwtScaleDraw::BottomScale);
    20.  
    21. scaleUpdateTimer->setInterval(1000);
    22. connect(scaleUpdateTimer, SIGNAL(timeout()),
    23. this, SLOT(updateScale()));
    24. scaleUpdateTimer->start();
    25. }
    26.  
    27. MainWindow::~MainWindow()
    28. {
    29. delete ui;
    30. }
    31.  
    32. void MainWindow::updateScale()
    33. {
    34. if (useScaleEngine->isChecked())
    35. {
    36. scaleWidget->setScaleDiv(engine.divideScale(limit, limit+1, 10, 10));
    37. } else
    38. {
    39. scaleWidget->setScaleDiv(QwtScaleDiv(limit, limit+1));
    40. }
    41. limit++;
    42. }
    To copy to clipboard, switch view to plain text mode 
    By default it starts out using a scale engine to create the QwtScaleDiv, which appears to work. If you uncheck the checkbox, I just get a flat line for the scale widget, no tickmarks, no values, etc.

  4. #4
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to set limits on a standalone QwtScaleWidget?

    and then hide all the x-axis scale widgets of each plot
    How did you hide the widgets...

    plot->axisWidget(QwtPlot::xBottom)->hide(); //I do not believe this will do.
    QwtPlot::updateLayout() //toggles hide to show for all enabled axes


    plot->enableAxis(QwtPlot::xBottom, false); //This will

    But...
    QwtPlot::updateLayout() //ignores axes that are not enabled

    Thus a heads up..

    I

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

    Default Re: How to set limits on a standalone QwtScaleWidget?

    Quote Originally Posted by SeanM View Post
    By default it starts out using a scale engine to create the QwtScaleDiv, which appears to work. If you uncheck the checkbox, I just get a flat line for the scale widget, no tickmarks, no values, etc.
    Sure because in this case you pass a scale division which has valid boundaries, but no ticks at all.

    It doesn't matter whether you create the ticks using a scale engine or you fill in the vectors manually - as long as the tick values are inside the boundaries. Note that tick labels are only at major ticks.

    Uwe

  6. #6
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set limits on a standalone QwtScaleWidget?

    How did you hide the widgets...
    I'm using this method:
    plot->enableAxis(QwtPlot::xBottom, false);
    But...
    QwtPlot::updateLayout() //ignores axes that are not enabled
    Unless I'm misunderstanding your point, I'm fine with disabled axes being ignored, since I'm not going to be using them.

Similar Threads

  1. setting scrollbar limits
    By tuli in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2012, 07:03
  2. limits for drawing a QwtPlotCurve
    By rambo83 in forum Qwt
    Replies: 1
    Last Post: 1st December 2009, 10:02
  3. Hitting memory limits for malloc() at about 1.7GB?
    By Skywalker in forum Qt Programming
    Replies: 7
    Last Post: 8th July 2009, 02:44
  4. QStandardItemModel limits
    By baray98 in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2008, 09:51

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.