我正在编写一个继承自QGraphicsItem和QWidget的类。我这样做的原因是因为我想使用setPos()和setRotation() (来自QGraphicsItem)来使它可拖动,并使用customContextMenuRequested信号(来自QWidget)。代码如下所示:
class MyClass: public QWidget, public QGraphicsItem {
Q_OBJECT
/* Variables and Methods here */
};
我不是QT的专家,以及它是如何在每一个细节上工作的。但是,通过测试代码,我感觉到MyClass
我正在学习Qt中的信号/插槽,我发现了一个问题。我需要创建我自己的插槽,当QGraphicsScene上的项目(在QGraphicsView中)被移动或选择时调用它。
我从一个简单的应用程序开始,它只有一个小部件,上面有graphicsView和label。我在我的窗口中创建了一个插槽,并将它连接到QGraphicsScene的信号,但是它没有被使用。我的错误在哪里?
以下是代码:
//MainWindow.h
//as generated by QtCreator, just added one slot to it
...omitted for brevity...
public slo
我有3个类Entity,Character和Item。当我这样做的时候
Character * Player = new Character(QRectF(0, 0, 50, 50), "player", theScene);
Player->setVelocityX(30)->setAttackPoint(10);
编译器告诉error: 'class Entity' has no member named 'setAttackPoint'。如何让Entity* setVelocityX(qreal vx);返回Character指
我使用Qt框架的QGraphicsScene。在场景中,我有一些QGraphicsItem,用户可以选择和移动。我希望有一个信息标签,其中显示当前移动选择的当前x和y坐标(可以包含许多项)。
我试过用信号changed of QGraphicsScene。但是,它是在将项目的x()和y()属性设置为新值之前触发的。所以标签总是显示第二坐标。如果一个人移动鼠标缓慢,显示并不是很错误。但是随着快速移动和突然停止,标签是错误的。我需要一个信号,是在现场改变后发射的。
我还试图重写QGraphicsItem的QGraphicsItem方法。但这是一样的。它是在改变之前被发射的。(新的坐标在此方法的参数
我想将一个QWidget放到一个QGraphicsView中,并使用QGraphicsProxyWidget使该小部件可选和可移动。(这对QGraphicsRectItem、QGraphicItem等非常有效)
这是我目前使用的代码:
// Create new QGraphicsScene and assign to graphicsView
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
// Create widget and add to scene
MyWidget *widget
我正在尝试创建可移动的矩形,下面是我的code.but,下面出现了3个错误。
invalid use of incomplete type 'class QGraphicsRectItem' rect->setFlag(QGraphicsItem::ItemIsMovable, true);
forward declaration of 'class QGraphicsItem' class QGraphicsItem;
incomplete type 'QGraphicsItem' used in nested name specif
我想移动QPushButton或QWidget在QGraphicsView中,例如QListWidet,QTableWidget等等。
所以,我使用了QGraphicsProxyWidget。
然后单击小部件并拖动。但它并没有移动。
我怎样才能移动QWidget?
这是我的密码。
ui->graphicsView->setGeometry(0,0,geometry().width(),geometry().height());
scene = new QGraphicsScene(0, 0, geometry().width(), geometry().height(), this
我已经从QGraphicsScene编写了一个派生类。在这一点上,我需要从场景中删除所有的项目,我希望这些项目被物理销毁(调用析构函数)。我尝试了以下几种方法:
QList<QGraphicsItem*> all = items();
for (int i = 0; i < all.size(); i++)
{
QGraphicsItem *gi = all[i];
removeItem(gi);
delete gi; // warning at this line
}
Qt创建器发出警告: warning: C4150:删除指向不完整类型‘QGrap
我有个小问题
我正在编写Petri网模拟器。
我有两个不同的课程
class PNItem : public QObject, public QGraphicsItem
...
和
class PNEdge : public QGraphicsLineItem
当我打电话给..。
QGraphicsItem *QGraphicsScene::ItemAt(//cursor position)
,有没有可能知道,我点击了什么项目?响应。什么项目是由ItemAt提供的项目?
我是编程新手,需要帮助。
我有一个类Station,它包含X和Y字段:
Class Station {
int x
int y
...
}
所有的电台都在QGraphicsScene上画圆圈和文字:
this->scene.addEllipse(x1, y1, diam, diam, pen, QBrush(...));
我需要一个函数getClickedStation,它正在等待单击一个QGraphicsScene,找到圆圈并返回接近其坐标的站点:
Station* getClickedStation(...) { ... }
有什么办法吗?
我试过这样做只是为了获得坐标:
QList