Anchor layout QGraphicsView
Hi there,
In my application I have a QGraphicsScene with lots of objects inside a QGraphicsView object that sits over a QMainWindow.
How can I make that QGraphicsView to be anchored inside the QMainWindow, so I can move it around with the mouse?
Thanks in advance.
10 replies
Not sure I understand exactly what you want to accomplish, but if you want to be able to move and resize the QGraphicsView freely inside the QMainWindow, you have to use a QMdiArea. But if you only have one QGraphicsView, I don’t really understand why you would want to do that.
It’s mostly a matter of style. Do you know the application Sibelius or even MuseScore? I want to make a graphicsview containing a musical score just like the one in that apps.
Ok, it works the way I expected except for one issue: the mousepressevents that were being handled correctly are not anymore. I cannot select items anymore inside my graphicsview. Also I can only move around the subwindow containing the graphicsview if I click (with the mouse) outside of it (e.g. over the mdiarea). Seems that subwindow mouseevents are not being caught.
Edit:
Actually, the events that aren’t being caught are the left click of the mouse and the mousemoveevent. Right clicks are caught… Bug?
Strange, I cannot see how using a QMdiArea would affect that, but it’s too long ago since I used one myself to remember if there was something special you had to do to make mouse press events work as usual. Maybe you should start a new thread with a more specific question about that, and see if someone else can help you out.
Update:
I installed a eventFilter in the class in order to try to solve these issues.
When I installed the filter with qApp->installEventFilter(this) the mouseevents worked properly inside the subwindow. Installing the filter over the class I am working in, I have the exact same issues as before… My app has a QMainWindow that is the main interface of the overall program, clicking a button another QMainWindow is invoked, which is the interface of the class I’m working in. So using qApp->installEventFilter(this), solves me these problems but gives me stack overflows when I click with the mouse and move it around in the rest of the app.
Any idea of how to solve this?
I just moved to this thread [qt-project.org].
You must log in to post a reply. Not a member yet? Register here!


