
Originally Posted by
blooglet
You can judge that yourself based on the code I provided.
Then what is the
correct way to prevent items from being selected in a
QGraphicsScene if my graphics scene is in a state where I don't want the user to be able to select items?
The correct way is to remove the ItemIsSelectable flag from the items. Another good way is to not call the base class implementation of mouse events in the scene but then you lose not only selection but also other features such as focus and item moving.
Apparently you are doing something wrong. My guess is you didn't override mouseDoubleClickEvent.
#include <QtGui>
public:
protected:
}
};
int main(int argc, char **argv){
GraphicsScene scene;
view.setScene(&scene);
view.show();
return app.exec();
}
#include <QtGui>
class GraphicsScene : public QGraphicsScene {
public:
GraphicsScene() : QGraphicsScene(){}
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *e) {
}
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e){}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
GraphicsScene scene;
QGraphicsView view;
view.setScene(&scene);
QGraphicsEllipseItem *item = scene.addEllipse(QRect(0,0,100,50), QPen(Qt::red), Qt::blue);
item->setFlag(QGraphicsItem::ItemIsSelectable);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks