Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Anchor layout QGraphicsView
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.
Sounds like you either want to set the QGraphicsView as the centralWidget of your QMainWindow, or use a QMdiArea as centralWidget and add your QGraphicsView as a subWindow of your QMdiArea.
At the moment the centralWidget inside the QMainWindow is parent of the QGraphicsView.
I only want to be able to move the QGraphicsView around with the mouse click/movement. Is that possible?
My QGraphicsView is a single sheet of work like a MS Word sheet.
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.
[quote author="ludde" date="1334055637"]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.[/quote]
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.
Haven't seen those applications, but it seems like a cool project. But, as I said, if you want a movable window within another window, use a QMdiArea.
Ok, I'll give it a try. Thank you very much. :)
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.
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.
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":http://qt-project.org/forums/viewthread/16310/.