6

I know how to make a QWidget (in Qt4 or Qt5) / QWindow (since Qt5) borderless, draw a custom title bar and manually implement mouse dragging to move the window on the screen by simply tracking the mouse position with some mouseMoveEvent and updating the window position.

However, this movement behaves different than the native one as implemented by the window manager. For example, moving the window near the screen's border can be interpreted as "fullscreen" or "split screen"; or windows snap to each other's borders, depending on the system / window manager. These things don't work if you implement the window movement like above.

Google Chrome / Chromium is only one example for an application which implements a custom window title bar and border, while still adapting to the native behavior of the window manager. I'm wondering whether Chrome implements these by itself (and detects the window manager and its configuration) or if there is some functionality in most window managers (clearly, this is still highly platform-dependent) for telling "start native window movement" and "stop native window movement" or similar.

Is something like that possible in Qt? If not, maybe using some other libraries like Qxt?

FYI: I'm mainly targeting Windows and Linux, where I see the difficulty that the user can have any window manager installed.

leemes
  • 44,967
  • 21
  • 135
  • 183
  • @BЈовић (edit): It's not Qt5 specific. The title was misleading. – leemes Feb 04 '13 at 22:04
  • 1
    Could this question be relevant to your problem (at least in Windows): http://stackoverflow.com/questions/11979278/wm-syscommand-sc-move-eats-up-mouse-events-and-mouse-up-is-not-fired –  Feb 04 '13 at 22:15
  • @Roku Excellent, thank you very much. This should work nice for Windows, I guess. So still looking for a solution which works in Linux. – leemes Feb 04 '13 at 22:18
  • ok, sorry. I thought I saw qt5 in your title – BЈовић Feb 04 '13 at 23:01
  • @BЈовић It was, but specifically for the `QWindow`, since it's only part of Qt5 and something different than `QWidget`. But since it was misleading, I removed it. – leemes Feb 05 '13 at 08:49
  • I think Qt does not have any cross-platform method for such a native behavior of the window manager. If you need that, you need to implement it yourself. A custom title bar and manually implemented mouse events may satisfy anything you need, i think, although it may need some work. – Eric Feb 08 '13 at 03:34

1 Answers1

2

Based on attempting the same with Qt4 recently, I fear the answer is, you need to tune this per-platform / per-window-manager. I expect patches to QWindow to improve the behaviour in this area would be accepted, but I'm not aware of any standard hook to tell the OS/window-manager what you're trying to achieve.

Equally Qt should be not be 'getting in the way' of solving this, it's simply an area where it can't do anything to help you in a generic way.

James Turner
  • 2,425
  • 2
  • 19
  • 24