gpt4 book ai didi

c++ - 如何将 QGraphicsProxyWidget 放在 QGraphicsGridLayout 上?

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:47 25 4
gpt4 key购买 nike

我正在Qt 5国际象棋项目。我将棋盘创建为 QWidget,现在我想添加动画棋子。这就是为什么我想在图形 View 上添加我的棋盘。我查阅了 Qt 文档 和其他几个网站。并编写了以下代码:

    QGraphicsProxyWidget* pProxy = scene->addWidget(board);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
layout->addItem(pProxy,0,0);
QGraphicsWidget *form = new QGraphicsWidget;
form->setLayout(layout);
scene->addItem(form);

我收到错误:

没有匹配函数来调用‘QGraphicsGridLayout::addItem(QGraphicsProxyWidget*&, int, int)

我找不到解决方法。应该使用一种转换或编写“板”作为 QGraphicsWidget 吗?

最佳答案

我会冒险猜测并建议您忘记使用...

#include <QGraphicsProxyWidget>

在这种情况下,编译器对 QGraphicsProxyWidget 的唯一了解就是它的前向声明。因此它不知道 QGraphicsProxyWidget 实际上是从 QGraphicsLayoutItem 继承的——正如 QGraphicsGridLayout::addItem 的第一个参数所要求的那样-- 并生成错误消息。如果添加 #include 就足够了。

关于c++ - 如何将 QGraphicsProxyWidget 放在 QGraphicsGridLayout 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58017988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com