3

I'm using QMdiSubWindow, I want to capture any input which is attempting to modify the size/shape/position of the window and filter/modify the resulting position and size so that the widget is aligned to a grid.

QResizeEvent seems to be too late, i.e. the window has already resized, layouts have already been calculated and often a complete repaint of the widget has been scheduled.

resizeEvent and eventFilter both just allow me to learn about the resize that has just occurred and 'undo' it if the change was undesirable, this is a massive performance problem for me (embedded device, slow graphics).

I'm currently catching QMouseEvents and modifying the reported cursor positions but this is messy and doesn't catch all cases where the window geometry changes.

Troyseph
  • 4,960
  • 3
  • 38
  • 61
  • Given you want such control over widget geometry is `QMdiArea`/`QMdiSubWindow` definitely the best option? Assuming you stick with it you could create the `QMdiSubWindow` with the `Qt::FramelessWindowHint` window flag set and then add the required move/resize functionality yourself. Tedious but it might prove easier than trying to selectively disable certain interactions. – G.M. Nov 18 '16 at 14:03
  • @G.M. geometry is a property of `QWidget` so any other choice would be equally awkward. I'm already subclassing it to capture and modify mouse events, I've also substituted my own move and resize actions. It is all working but the code feels bloaty and weirdly hacked in. There are also some bugs regarding sizes updating through any other means. – Troyseph Nov 18 '16 at 16:07

1 Answers1

0

If you are resizing by dragging window border than u should catch event like QEvent::NonClientAreaMouseButtonPress, checkout for more here - QEvent::Type

You can install watcher for checking out of changing window sizes and having a flag about NonClientDrag(for example).
But the question is what to do when user pushing "maximize" button or just a win+↑ (in WinOS), in other hand this changes are almost immediate, so you should not worry about them.

Preonix
  • 53
  • 1
  • 1
  • 9
  • I'm not sure how this is any different to what I'm already doing, capturing mouse events... I don't need to capture `NonClientAreaMouseButtonPress` because my `QMdiSubWindow` is fully contained within a larger `QMdiArea`. Also my question is more about how to prevent an event from happening, how to learn an event wants to happen, but silence or modify it before it does. – Troyseph Oct 10 '17 at 09:08
  • Then probably you should check out the [The Event System](http://doc.qt.io/qt-5/eventsandfilters.html), then something about qApp()->installEventFilter(...). You also can lock and unlock fixedSize flag in your SubWindow. As for me I'm now in search of solution to do something before ResizeEvent but not after – Preonix Oct 11 '17 at 17:03
  • 1
    From the Docs: `The QResizeEvent class contains event parameters for resize events. Resize events are sent to widgets that have been resized.` This is what is in my way, I want to know about the resize **before** it happens... – Troyseph Oct 13 '17 at 08:36
  • I think then you should use WinAPI or whatever API of needed OS. I think that default mechanism of resizing is tooked from OS and only then u catch resize event in Qt. Probably there is one suggestion: trying to do your own resizing mechanism which will change FixedSizes of your widget. I wonder will it work or not because its only my guess – Preonix Oct 16 '17 at 11:45