我试图通过将一个QColor从QQuickPaintedItem传递给QML来设置自定义QQuickPaintedItem的QColor属性。我尝试了以下几点:
QML代码:
m_DisplayScreens[m_DisplayScreens.length].backgroundColor = m_Model.getBackgroundColor(i_Timer);m_DisplayScreens是我的自定义QML小部件的列表。通过这样的操作,我可以很好地设置backgroundColor属性。
DisplayScreen
{
backgroundColor: "Red"
}"m_Model“对象只是一个QObject,它是QML表单的‘后端’。getBackgroundColor的代码如下:
Q_INVOKABLE QString getBackgroundColor(int index);
QString CountDownPanelModel::getSegmentColor(int index)
{
return "#003300";
}具体错误是: xxx.js:19: TypeError: TypeError
任何帮助都将不胜感激。我已经用头撞了好几个小时。
谢谢,
联合执行委员会
第一编辑:
好了,各位,这是我在返回QColor时的尝试;
class CountDownPanelModel : public QObject
{
Q_OBJECT
public:
explicit CountDownPanelModel(QObject *parent = 0);
~CountDownPanelModel() = default;
Q_INVOKABLE QColor getBackgroundColor(int index);
Q_INVOKABLE QColor getSegmentColor(int index);
};
QColor CountDownPanelModel::getBackgroundColor(int index)
{
return QColor(44, 44, 44);
//return m_TimerList->at(index)->getTimerData()->getBackgroundColor();
}
QColor CountDownPanelModel::getSegmentColor(int index)
{
return QColor(200, 200, 200);
//return m_TimerList->at(index)->getTimerData()->getSegmentColor();
}使用QColor的结果与使用QString相同。我得到“类型错误”的行,我指定的颜色。例如:
var m_DisplayScreens = [];
function createDisplays()
{
m_DisplayScreens = [];
var timerCount = m_Model.getTimerCount();
var bg = m_Model.getBackgroundColor(0);
var fg = m_Model.getSegmentColor(0)
for (var i_Timer = 0;
i_Timer < timerCount;
++i_Timer)
{
var component = Qt.createComponent("DynamicSevenSegmentDisplay.qml");
var display = component.createObject(m_Panel);
display.initialize(m_Model.getSevenSegmentDisplayInitializer())
display.y = 100 * (i_Timer);
m_DisplayScreens[m_DisplayScreens.length] = display;
m_DisplayScreens[m_DisplayScreens.length].backgroundColor = m_Model.getBackgroundColor(i_Timer);
m_DisplayScreens[m_DisplayScreens.length].segmentColor = m_Model.getSegmentColor(i_Timer)
}
m_Panel.height = 100 * timerCount;
}为了完整起见,这里是DynamicSevenSegmentDisplay.qml
SevenSegmentDisplayScreen
{
y: 0
height: 100
width: parent.width - x
backgroundColor: "Black"
borderPercentage: 10
displayCount: 20
text: "1234567890"
anchors.left: m_SettingsButton.right
anchors.leftMargin: 8
}我完全不明白为什么我不能将QColor分配给backgroundColor。调试器只是在“value”列中没有显示任何内容。我想这是'null‘的JS版本。
发布于 2014-10-01 00:37:59
这不是一个明确的答案,但我发现了几个问题。我以前是使用Linux开发的。最近,我转到Ubuntu,发现了在C++和QML之间传递数据的几个问题。我收到一条关于CRC错过比赛的消息。
“在”/usr/lib/x86_64-linux-gnu/dri/i 915_dri.so“中找到的调试信息”不匹配“/usr/lib/x86_64-linux-gnu/dri/i 965_dri.so”(CRC不匹配)。
所以这也可能是问题的一部分。但在大多数情况下,它看起来像是我的开发机器。
https://stackoverflow.com/questions/26090962
复制相似问题