C++ QQuickPaintedItem在QML设计器中不可见
我创建了QQuickPaintedItem类,该类负责使用可重写的paint()方法绘制UI内容。组件放置在Qml中,但我无法在designer中看到它。但我可以在运行时看到结果。 我在跟踪 什么都不起作用,我真的需要在qml设计器中查看输出,而不是在运行时 正如我所关注的 下面是头文件的源代码C++ QQuickPaintedItem在QML设计器中不可见,c++,qt,qml,C++,Qt,Qml,我创建了QQuickPaintedItem类,该类负责使用可重写的paint()方法绘制UI内容。组件放置在Qml中,但我无法在designer中看到它。但我可以在运行时看到结果。 我在跟踪 什么都不起作用,我真的需要在qml设计器中查看输出,而不是在运行时 正如我所关注的 下面是头文件的源代码 class TextBalloon : public QQuickPaintedItem { Q_OBJECT Q_PROPERTY(bool rightAligned READ isRightAlig
class TextBalloon : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(bool rightAligned READ isRightAligned WRITE setRightAligned NOTIFY rightAlignedChanged)
public:
TextBalloon(QQuickItem *parent = 0);
void paint(QPainter *painter);
bool isRightAligned();
void setRightAligned(bool rightAligned);
private:
bool rightAligned;
signals:
void rightAlignedChanged();
};
和定义
TextBalloon::TextBalloon(QQuickItem *parent)
: QQuickPaintedItem(parent)
, rightAligned(false){}
void TextBalloon::paint(QPainter *painter){
QBrush brush(QColor("#007430"));
painter->setBrush(brush);
painter->setPen(Qt::NoPen);
painter->setRenderHint(QPainter::Antialiasing);
QSizeF itemSize = size();
painter->drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10);
if (rightAligned)
{
const QPointF points[3] = {
QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0),
QPointF(itemSize.width() - 20.0, itemSize.height()),
QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0),
};
painter->drawConvexPolygon(points, 3);
}
else
{
const QPointF points[3] = {
QPointF(10.0, itemSize.height() - 10.0),
QPointF(20.0, itemSize.height()),
QPointF(30.0, itemSize.height() - 10.0),
};
painter->drawConvexPolygon(points, 3);
}
}
这是qml文件
ListModel {
id: balloonModel
ListElement {
balloonWidth: 200
}
ListElement {
balloonWidth: 120
}
}
ListView {
anchors.bottom: controls.top
anchors.bottomMargin: 2
anchors.top: parent.top
id: balloonView
delegate: TextBalloon {
anchors.right: index % 2 == 0 ? undefined : parent.right
height: 60
rightAligned: index % 2 == 0 ? false : true
width: balloonWidth
}
model: balloonModel
spacing: 5
width: parent.width
}
请帮助我,我真的需要在qml设计器中查看绘制的输出
或者请建议另一种绘画方式,通过它我可以在qml designer中看到输出。
谢谢:)设计中似乎缺少此功能。我将使用任何其他绘画方法。设计中似乎缺少此功能。我将使用任何其他绘画方法。