简体   繁体   English

QDial设置范围从0.00到10.00至小部件显示

[英]QDial set range from 0.00 to 10.00 to widget displays

I have a class that connects a Lcd display with a dial and when you rotate the dial you get values on the lcd like this 我有一个将LCD显示屏和转盘连接起来的类,当您旋转转盘时,您会像这样在LCD上获得值

#ifndef SLIDELCD_H
#define SLIDELCD_H

#include <QDial>
#include <QVBoxLayout>
#include <QLCDNumber>
#include "CustomDial.h"
class SlideLcd: public QWidget
{
Q_OBJECT
public:
SlideLcd(QWidget *parent=nullptr);
private:
CustomDial *dial;
QLCDNumber *lcd;
QVBoxLayout *layout;
};

SlideLcd::SlideLcd(QWidget *parent)
               :QWidget(parent)
{
dial = new CustomDial;
dial->setNotchesVisible(true);
lcd = new QLCDNumber;
connect(dial, SIGNAL(valueChanged(int)), lcd , SLOT(display(int)));
layout = new QVBoxLayout;
layout->addWidget(lcd);
layout->addWidget(dial);
setLayout(layout);
}

I know that with QDial::setRange(0,100) you can set the range from 0-100 but is there any way to set ranges like 0.00 to 100.00 我知道使用QDial :: setRange(0,100)可以将范围设置为0-100,但是有什么办法可以设置范围,例如0.00到100.00

Given that there's no way to specify QDial range using double , you should provide an extra slot to catch the valueChanged signal, edit the value there and pass the edited value to display method of lcd . 鉴于无法使用double来指定QDial范围,您应该提供一个额外的插槽来捕获valueChanged信号,在其中编辑值,并将编辑后的值传递给lcd display方法。

So, in your widget class: 因此,在您的小部件类中:

private slots:
  void dialValueChanged(int value);

Set dial range to 0-10000 in constructor: 在构造函数中将拨号范围设置为0-10000:

dial->setMinimum(0);
dial->setMaximum(10000);

then connect the new slot: 然后连接新插槽:

connect(dial, SIGNAL(valueChanged(int)), this , SLOT(dialValueChanged(int)));

The slot definition is like this: 插槽定义如下:

void SlideLcd::dialValueChanged(int value)
{
  double v = (double)((double)value / 100);
  lcd->display(v);
}

This way, as the dial value changes from 0 to 10000, your lcd will display numbers in range 0.00 to 100.00, accordingly. 这样,当拨号值从0更改为10000时,您的LCD将相应显示0.00到100.00范围内的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM