Qt에서 클릭을 처리하는 데 문제가 있습니다. 나는 다음과 같은 클래스가 :이 프로그램을 실행할 때Qt 오브젝트 신호가 메소드 (핸들러)에 연결되지 않았습니다.
MyRectItem *i = new MyRectItem(-d, -d, d, d);
i->setPen(QPen(Qt::darkBlue));
i->setPos(150,150);
// canvas is a QGraphicsScene
canvas.addItem(i);
i->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
QObject::connect(&canvas, SIGNAL(selectionChanged(bool)), this, SLOT(test()));
, 원이 canvas
에 표시되지만 때 :
class MyRectItem : public QObject, public QGraphicsEllipseItem{
Q_OBJECT
public:
MyRectItem(double x,double y, double w, double h)
: QGraphicsEllipseItem(x,y,w,h)
{}
public slots:
void test() {
QMessageBox::information(0, "This", "Is working");
printf("asd");
}
signals:
void selectionChanged(bool newState);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) {
if (change == QGraphicsItem::ItemSelectedChange){
bool newState = value.toBool();
emit selectionChanged(newState);
}
return QGraphicsItem::itemChange(change, value);
}
};
가 지금은 신호에 슬롯을 연결하려는를, 나는 다음을 수행
Object::connect: No such signal QGraphicsScene::selectionChanged(bool)
어떤 제안 : 원 아무 일도 발생하지 않고 콘솔은 다음과 같은 표시를 클릭?