Hello
I try to use the 'Knob'. I turn the 'Knob' but the value of the label isn't changed.
66.png
Knob.pro
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
QWT_LOCATION = c:/Qwt-6.0.2
INCLUDEPATH += $${QWT_LOCATION}/include
LIBS = -L$${QWT_LOCATION}/lib \
-lqwt
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
QWT_LOCATION = c:/Qwt-6.0.2
INCLUDEPATH += $${QWT_LOCATION}/include
LIBS = -L$${QWT_LOCATION}/lib \
-lqwt
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char **argv)
{
MainWindow mw;
mw.show();
return app.exec();
}
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow mw;
mw.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
signals:
private slots:
void setValueOfLabel(double value);
private:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QLabel;
class QwtKnob;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
signals:
private slots:
void setValueOfLabel(double value);
private:
QLabel *label;
QwtKnob *knob;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include <qwt_knob.h>
#include <QVBoxLayout>
#include <QWidget>
#include <QLabel>
MainWindow
::MainWindow(QWidget *parent
) :{
mainLayout->addWidget(label, 0, Qt::AlignCenter);
mainLayout->addWidget(knob);
window->setLayout(mainLayout);
setCentralWidget(window);
this->setWindowTitle(tr("Knob"));
connect(knob, SIGNAL(valueChanged(double)), label, SLOT(setValueOfLabel(double )));
}
void MainWindow::setValueOfLabel(double value)
{
label
->setText
(QString::number(value
));
}
#include "mainwindow.h"
#include <qwt_knob.h>
#include <QVBoxLayout>
#include <QWidget>
#include <QLabel>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
knob = new QwtKnob;
label = new QLabel(QString::number(knob->value()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(label, 0, Qt::AlignCenter);
mainLayout->addWidget(knob);
QWidget *window = new QWidget;
window->setLayout(mainLayout);
setCentralWidget(window);
this->setWindowTitle(tr("Knob"));
connect(knob, SIGNAL(valueChanged(double)), label, SLOT(setValueOfLabel(double )));
}
void MainWindow::setValueOfLabel(double value)
{
label->setText(QString::number(value));
}
To copy to clipboard, switch view to plain text mode
Ivan
Thanks
Bookmarks