简体   繁体   English

在 Pyqt 中,如何通过空的小部件空间启用拖动/移动窗口?

[英]In Pyqt, how do I enable dragging/moving windows by the empty widget space?

Main Qt apps, and AFAIK most KDE apps let you drag windows around not just by their titlebar, but using any empty space on the window.主要的 Qt 应用程序和 AFAIK 大多数 KDE 应用程序让您不仅可以通过标题栏拖动窗口,还可以使用窗口上的任何空白空间。 For some reason, a basic Pyqt app like this doesn't appear to let you do that:出于某种原因,像这样的基本 Pyqt 应用程序似乎不允许您这样做:

from PyQt4.QtGui import *
import sys

a = QApplication(sys.argv)
w = QWidget()
w.show()
sys.exit(a.exec_())

I'm looking to enable dragging the window around by the widgets in it.我希望能够通过其中的小部件拖动窗口。 I found an existing StackOverflow question and answer , but it doesn't use the window manager to actually move the window, which (1) isn't like other apps, (2) isn't as pretty as when the window manager does it. 我发现了一个现有的 StackOverflow 问题和答案,但它并没有使用窗口管理器来实际移动窗口,这 (1) 不像其他应用程序,(2) 不像窗口管理器那样漂亮.

So my question is, what am I missing?所以我的问题是,我错过了什么? How do I just pass an unused click/drag event up to the window manager for moving the window?如何将未使用的单击/拖动事件传递给窗口管理器以移动窗口?

It turns out that for a window to be draggable by the extra space on it, you need to inherit it from QMainWindow or QDialog, not just QWidget.事实证明,要让窗口上的额外空间可拖动,您需要从 QMainWindow 或 QDialog 继承它,而不仅仅是 QWidget。 There you have it.你有它。

请注意,这是一个 KDE 功能,在小部件样式 Oxygen 和 Breeze 中实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM