sens.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "sens.h"
  2. #include <QLCDNumber>
  3. #include <QSlider>
  4. #include <QGridLayout>
  5. Sens::Sens(QWidget *parent) :
  6. QWidget(parent)
  7. {
  8. QLCDNumber *lcd = new QLCDNumber(2);
  9. lcd->setSegmentStyle(QLCDNumber::Flat);
  10. lcd->display(5);
  11. QSlider *slider = new QSlider(Qt::Vertical);
  12. slider->setRange(1,10);
  13. slider->setValue(5);
  14. connect(slider,SIGNAL(valueChanged(int)),
  15. lcd,SLOT(display(int)));
  16. //connect(slider,SIGNAL(valueChanged(int)),
  17. //this,SLOT(setValue(int)));
  18. QGridLayout *grid = new QGridLayout();
  19. grid->addWidget(lcd,0,1);
  20. grid->addWidget(slider,0,0,0,1);
  21. //grid->setColumnStretch(1,1);
  22. grid->setRowStretch(0,10);
  23. grid->addItem(new QSpacerItem(100, 50, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding),1, 1);
  24. this->setLayout(grid);
  25. }
  26. void Sens::setRange(int minValue, int maxValue)
  27. {
  28. if (minValue < 1 || maxValue > 11|| minValue > maxValue) {
  29. qWarning("LCDRange::setRange(%d, %d)\n"
  30. "\tRange must be 0..10\n"
  31. "\tand minValue must not be greater than maxValue",
  32. minValue, maxValue);
  33. return;
  34. }
  35. slider->setRange(minValue, maxValue);
  36. }
  37. int Sens::value() const
  38. {
  39. return slider->value();
  40. }
  41. void Sens::setValue(int value)
  42. {
  43. slider->setValue(value);
  44. }