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
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
public slots:
void updateScale();
private:
Ui::MainWindow *ui;
double limit;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void updateScale();
private:
Ui::MainWindow *ui;
QTimer* scaleUpdateTimer;
QwtScaleWidget* scaleWidget;
double limit;
QVBoxLayout* vbox;
QCheckBox* useScaleEngine;
};
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
limit = 0;
useScaleEngine
= new QCheckBox("Use Scale Engine",
this);
scaleUpdateTimer
= new QTimer(this);
vbox->addWidget(useScaleEngine);
vbox->addWidget(scaleWidget);
centralWidget()->setLayout(vbox);
useScaleEngine->setChecked(true);
scaleUpdateTimer->setInterval(1000);
connect(scaleUpdateTimer, SIGNAL(timeout()),
this, SLOT(updateScale()));
scaleUpdateTimer->start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updateScale()
{
if (useScaleEngine->isChecked())
{
scaleWidget->setScaleDiv(engine.divideScale(limit, limit+1, 10, 10));
} else
{
}
limit++;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
limit = 0;
vbox = new QVBoxLayout(this);
useScaleEngine = new QCheckBox("Use Scale Engine",this);
scaleUpdateTimer = new QTimer(this);
scaleWidget = new QwtScaleWidget(this);
vbox->addWidget(useScaleEngine);
vbox->addWidget(scaleWidget);
centralWidget()->setLayout(vbox);
useScaleEngine->setChecked(true);
scaleWidget->setAlignment(QwtScaleDraw::BottomScale);
scaleUpdateTimer->setInterval(1000);
connect(scaleUpdateTimer, SIGNAL(timeout()),
this, SLOT(updateScale()));
scaleUpdateTimer->start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updateScale()
{
if (useScaleEngine->isChecked())
{
QwtLinearScaleEngine engine;
scaleWidget->setScaleDiv(engine.divideScale(limit, limit+1, 10, 10));
} else
{
scaleWidget->setScaleDiv(QwtScaleDiv(limit, limit+1));
}
limit++;
}
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.
Bookmarks