// Volume Slider Example by Joachim Michaelis 2007 // Install QT and compile using this command: // qmake -project && qmake && make #include #include #include #include #include #include #include #include class MyWidget : public QWidget { Q_OBJECT // QT specific public: MyWidget(QWidget *parent = 0) : QWidget(parent) { QPushButton *quit = new QPushButton(tr("Quit")); quit->setFont(QFont("sans-serif", 9)); lcd = new QLabel(); lcd->setFont(QFont("sans-serif", 9)); QSlider *slider = new QSlider(Qt::Horizontal); slider->setRange(0, 1000); connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slotmodtager(int))); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(lcd); layout->addWidget(slider); layout->addWidget(quit); setLayout(layout); slider->setValue(631); } public slots: // QT specific void slotmodtager(int x) { char label[60]; float amplitude = powf(x/1000.0f, 3) * exp10(12.0f/20.0f); float db = -1000; if (amplitude>0) db = 20*log10(amplitude); sprintf(label, "Slider pos.: %d\nAmplitude: %02.01f%%\nBoost: %+02.01f dB", x, amplitude*100, db); lcd->setText(label); } private: QLabel *lcd; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); MyWidget widget; widget.show(); widget.resize(300,130); return app.exec(); } #include "slider.moc" // QT specific