简体   繁体   English

自定义窗口小部件上的float类型的Q_PROPERTY未出现在属性编辑器中

[英]Q_PROPERTY of type float on custom widget does not appear in the Property Editor

I'm working on a custom widget and wanted to make some float type properties. 我正在开发一个自定义窗口小部件,并希望创建一些浮点类型的属性。 Unfortunately it doesn't seem that Qt Creator is a fan of those float type properties and isn't showing them in the property editor. 不幸的是,似乎Qt Creator并不喜欢那些浮点类型的属性,并且没有在属性编辑器中显示它们。 All of my other properties work fine (int, bool, QString). 我的所有其他属性都可以正常工作(int,bool和QString)。 Here's an example of how I declare the properties. 这是我如何声明属性的示例。

In the header file: 在头文件中:

Q_PROPERTY( float Value
            READ getValue
            WRITE setValue
            RESET resetValue )
float Value;

// ...

float getValue();
void resetValue();
void setValue( float value );

And in the source file: 并在源文件中:

float MyWidget::getValue()
{
    return Value;
}
void MyWidget::resetValue()
{
    Value = 0;
}
void MyWidget::setValue( float value )
{
    Value = value;
}

Is there something special that needs to be done before floats can be used for widget properties? 在将浮点数用于窗口小部件属性之前,是否需要做一些特殊的事情?

double should work as for example QWidget::windowOpacity is a double type and it is displayed in the property editor. double应该像QWidget::windowOpacity工作,它是一种double类型,并显示在属性编辑器中。 I am not sure why float doesn't work, but usually when some properties don't display in the property editor it is because it doesn't know what editor to use. 我不确定为什么float不起作用,但是通常当某些属性未显示在属性编辑器中时,这是因为它不知道要使用哪个编辑器。

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

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