写一个DoubleSPinbox的样式表,编辑时文字变绿色,正常是白色
时间: 2024-02-12 21:07:14 浏览: 16
下面是一个简单的DoubleSpinBox样式表,可以实现编辑时文字变为绿色,正常为白色:
```
QDoubleSpinBox {
color: white;
background-color: #333333;
border: 2px solid #555555;
border-radius: 4px;
padding: 2px 4px;
}
QDoubleSpinBox:focus {
color: green;
background-color: #444444;
border: 2px solid #00FF00;
border-radius: 4px;
padding: 2px 4px;
}
```
你可以将以上代码复制到你的样式表中。
相关问题
doublespinbox设置不可编辑
要设置QDoubleSpinBox不可编辑,可以使用setReadOnly方法。将其设置为True即可禁用编辑。示例代码如下:
```python
from PyQt5 import QtWidgets
app = QtWidgets.QApplication([])
spinbox = QtWidgets.QDoubleSpinBox()
spinbox.setReadOnly(True)
spinbox.show()
app.exec_()
```
此代码将创建一个QDoubleSpinBox并将其设置为不可编辑。
QT 中DoubleSpinBox的代码创建
以下是在 Qt 中创建一个 DoubleSpinBox 的代码示例:
```cpp
#include <QDoubleSpinBox>
// 在某个函数中创建 DoubleSpinBox
QDoubleSpinBox* doubleSpinBox = new QDoubleSpinBox(this); // this 表示父对象,可以是 QMainWindow、QWidget 等
// 设置 DoubleSpinBox 的属性
doubleSpinBox->setMinimum(0.0);
doubleSpinBox->setMaximum(10.0);
doubleSpinBox->setSingleStep(0.1);
doubleSpinBox->setValue(5.0);
// 连接 DoubleSpinBox 的信号和槽函数
connect(doubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &MyClass::onDoubleSpinBoxValueChanged);
```
其中,`setMinimum()` 和 `setMaximum()` 分别设置 DoubleSpinBox 的最小值和最大值;`setSingleStep()` 设置步长;`setValue()` 设置初始值;`connect()` 连接 DoubleSpinBox 的信号和槽函数。
`QOverload<double>` 是一个模板类,用于指定函数的参数类型。在这个例子中,我们使用了 `QOverload<double>::of()` 来指定 `valueChanged` 信号的参数类型为 `double`,并将其连接到 `onDoubleSpinBoxValueChanged` 槽函数上。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)