【问题标题】:QGraphicsItem itemChange function doesn't match with the item's state?QGraphicsItem itemChange 函数与项目状态不匹配?
【发布时间】:2014-11-06 14:53:33
【问题描述】:

我使用了我自己的子类中的以下 itemChange 函数来触发信号:

    QVariant WayPointItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
    {
        if (change == QGraphicsItem::ItemSelectedChange){
            emit selcState(value.toBool());
        }
        return QGraphicsItem::itemChange(change, value);
    }

selcState 信号连接到一个槽为:

void WaypointLineItem::toggleText(bool value)
{
    if (wp->isSelected()) //wp is the waypointitem which emit the signal selcState()
        text.show();
    else
        text.hide();
}

我发现当我选择一个waypointitem时,它确实触发了itemChange函数,并且QGraphicsItem::ItemSelectedChange的bool值也是正确的。 但是,当涉及到插槽时, wp->isSelected() 返回的值是不同的。 怎么会这样,有什么解决办法吗?

【问题讨论】:

    标签: c++ qt qgraphicsitem


    【解决方案1】:

    当所选状态即将更改时, QGraphicsItem::ItemSelectedChange被调用。这意味着新的选中状态在value 参数中。

    您必须对 QGraphicsItem::ItemSelectedHasChanged 做出反应,其中所选状态已更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      • 2012-12-08
      相关资源
      最近更新 更多