【问题标题】:How to put QGraphicsProxyWidget on QGraphicsGridLayout?如何将 QGraphicsProxyWidget 放在 QGraphicsGridLayout 上?
【发布时间】:2020-01-20 21:35:47
【问题描述】:

我正在 Qt 5 上开展一个国际象棋项目。我将棋盘创建为QWidget,现在我想添加动画国际象棋人物。这就是为什么我想在图形视图上添加我的棋盘。我查阅了 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);

我收到错误:

no matching function for call to ‘QGraphicsGridLayout::addItem(QGraphicsProxyWidget*&, int, int)

我找不到解决方法。应该使用一种演员表还是写“板”作为QGraphicsWidget?

【问题讨论】:

    标签: c++ qt graphics qgraphicsview


    【解决方案1】:

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

    #include <QGraphicsProxyWidget>
    

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

    【讨论】:

      猜你喜欢
      • 2011-02-09
      • 1970-01-01
      • 2017-01-09
      • 1970-01-01
      • 2021-02-01
      • 1970-01-01
      • 2013-05-03
      • 2023-03-09
      • 2013-07-27
      相关资源
      最近更新 更多