April 10, 2012

tcampos tcampos
Lab Rat
19 posts

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

April 10, 2012

ludde ludde
Ant Farmer
325 posts

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.

April 10, 2012

tcampos tcampos
Lab Rat
19 posts

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.

April 10, 2012

ludde ludde
Ant Farmer
325 posts

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.

April 10, 2012

tcampos tcampos
Lab Rat
19 posts
ludde wrote:
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.

April 10, 2012

ludde ludde
Ant Farmer
325 posts

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.

April 10, 2012

tcampos tcampos
Lab Rat
19 posts

Ok, I’ll give it a try. Thank you very much. :)

April 11, 2012

tcampos tcampos
Lab Rat
19 posts

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?

April 11, 2012

ludde ludde
Ant Farmer
325 posts

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.

April 11, 2012

tcampos tcampos
Lab Rat
19 posts

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?

April 12, 2012

tcampos tcampos
Lab Rat
19 posts

I just moved to this thread [qt-project.org].

 
  ‹‹ Sample Code for the MFC to Qt Migration Guide      Image is not displaying on pushbutton ››

You must log in to post a reply. Not a member yet? Register here!