ngugc
6th May 2012, 10:17
On Windows 7. Qt Creator 2.4.1 .
The project is compiled using MinGW.
The main code:
class DiagramItem : public QGraphicsObject
....
DiagramItem::DiagramItem()
{
//setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
//setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setCursor(Qt::OpenHandCursor);
}
void DiagramItem::contextMenuEvent(QGraphicsSceneContex tMenuEvent *event)
{
if( isSelected() ) {
QMessageBox::information(NULL, "Mosquito", "Selected.", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
}
QGraphicsItem::contextMenuEvent( event );
}
void DiagramItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
if (event->button() == Qt::LeftButton) {
if( contains( event->pos() ) ) {
scene()->clearSelection();
setSelected(true);
if( isSelected() ) {
QMessageBox::information(NULL, "Mosquito", "Selected.", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
}
//QMessageBox::information(NULL, "Mosquito", "Left Clicked.", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
}
}
QGraphicsItem::mouseReleaseEvent( event );
}
isSelected() in contextMenuEvent returns false without setFlag(QGraphicsItem::ItemIsMovable, true) in the ctor.
Why "selectable" property is related to "movable" property?
I don't want to make the item movable. How to make it seletable without movable?
The attachment is the code project.
The project is compiled using MinGW.
The main code:
class DiagramItem : public QGraphicsObject
....
DiagramItem::DiagramItem()
{
//setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
//setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setCursor(Qt::OpenHandCursor);
}
void DiagramItem::contextMenuEvent(QGraphicsSceneContex tMenuEvent *event)
{
if( isSelected() ) {
QMessageBox::information(NULL, "Mosquito", "Selected.", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
}
QGraphicsItem::contextMenuEvent( event );
}
void DiagramItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
if (event->button() == Qt::LeftButton) {
if( contains( event->pos() ) ) {
scene()->clearSelection();
setSelected(true);
if( isSelected() ) {
QMessageBox::information(NULL, "Mosquito", "Selected.", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
}
//QMessageBox::information(NULL, "Mosquito", "Left Clicked.", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
}
}
QGraphicsItem::mouseReleaseEvent( event );
}
isSelected() in contextMenuEvent returns false without setFlag(QGraphicsItem::ItemIsMovable, true) in the ctor.
Why "selectable" property is related to "movable" property?
I don't want to make the item movable. How to make it seletable without movable?
The attachment is the code project.