Quote Originally Posted by wysota View Post
I wouldn't "disable" mouse events in the scene. I would just gave a flag set in the scene according to the state of the list box. Then if the flag is set (something is selected) I would do the main thing the event is supposed to do, otherwise I would just emit a signal with mouse click position so that you can connect to it and set up the labels.
I would also do it that way but I have no idea how to work it out in qt. My problem is I don't know how to communication between the 2 widgets. I am still new to qt.

below are codes I did but got stuck halfway.

Mainwindow.h
Qt Code:
  1. ....
  2. private:
  3. QLabel *posX;
  4. QLabel *posY;
  5. QListWidget *area;
  6. mapscene *scene;
To copy to clipboard, switch view to plain text mode 

Mainwindow.cpp
Qt Code:
  1. MainWindow::MainWindow(QWidget *parent)
  2. : QMainWindow(parent)
  3. {
  4. posX = new QLabel;
  5. posX->setMinimumWidth(50);
  6. posX->setFrameShape(QFrame::Box);
  7.  
  8. posY = new QLabel;
  9. posY->setMinimumWidth(50);
  10. posY->setFrameShape(QFrame::Box);
  11.  
  12. area = new QListWidget;
  13. area->setMaximumWidth(180);
  14. area->setMinimumHeight(300);
  15. //assume all items added
  16.  
  17. scene = new mapscene;
  18. scene->setSceneRect(0, 0, 600, 600);
  19. }
To copy to clipboard, switch view to plain text mode 

mapscene.h
Qt Code:
  1. class mapscene : public QGraphicsScene
  2. {
  3. public:
  4. mapscene();
  5.  
  6. protected:
  7. void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
  8. void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
  9.  
  10. private:
  11. };
To copy to clipboard, switch view to plain text mode 

mapscene.cpp
Qt Code:
  1. const int ellsize = 5;
  2.  
  3. mapscene::mapscene()
  4. {
  5. item->setBrush(Qt::red);
  6. addItem(item);
  7. }
  8.  
  9. void mapscene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
  10. {
  11. //check status of listbox. How to check?
  12.  
  13. removeItem(item);
  14.  
  15. item->setRect(mouseEvent->scenePos().x(),mouseEvent->scenePos().y(),ellsize, ellsize);
  16. addItem(item);
  17.  
  18. //update posX and posY (Qlabel of Mainwindow). How to update?
  19.  
  20. QGraphicsScene::mousePressEvent(mouseEvent);
  21. }
  22.  
  23. void mapscene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
  24. {
  25. QGraphicsScene::mouseReleaseEvent(mouseEvent);
  26. }
To copy to clipboard, switch view to plain text mode