python - 设置自定义标题栏小部件会更改 Windows 上的窗口标志

标签 python qt pyqt pyside qdockwidget

我正在实现一个自定义小部件,以将其用作可停靠窗口上的标题栏。我的问题只出现在 Windows 上,即当停靠窗口漂浮时窗口边框消失。

似乎问题在于,仅在 Windows 上,窗口标志被更改。 IE。当我这样做时:

   print dock_window.windowFlags()
   dock_window.setTitleBarWidget(title_bar)
   print dock_window.windowFlags()

它打印出前后不同的标志设置。 然而,它在 linux 上保持不变,边界保持不变。

我的问题是,如何恢复窗口边框?

更新:由于自定义标题栏在 anchor 接窗口 float 时覆盖了边框标志,我如何编辑 anchor 接窗口使其具有某种边框? (停靠窗口在 float 时有一个自定义标题栏是至关重要的。)

最佳答案

根据这个answer这是预期的行为。

来自documentation setTitleBarWidget 的:

If a title bar widget is set, QDockWidget will not use native window decorations when it is floated.

那么 Linux 做错了吗?

无论如何,作为 Windows 的解决方法,我从 PySide/PyQt 的答案中实现了这个想法(在 float 之前取消设置标题栏小部件)。

from PySide import QtGui, QtCore

class MyDockWidget(QtGui.QDockWidget):

    def __init__(self, title_widget):
        super().__init__()
        self.title_widget = title_widget
        self.toggle_title_widget(False)
        self.topLevelChanged.connect(self.toggle_title_widget)

    def toggle_title_widget(self, off):
        if off:
            self.setTitleBarWidget(None)
        else:
            self.setTitleBarWidget(self.title_widget)


app = QtGui.QApplication([])

w = QtGui.QMainWindow()
t = QtGui.QLabel('Title')
d = MyDockWidget(t)
w.addDockWidget(QtCore.Qt.LeftDockWidgetArea, d)
w.show()

app.exec_()

至少它在 float 时保持标准装饰。

关于python - 设置自定义标题栏小部件会更改 Windows 上的窗口标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28502134/

相关文章:

python - 使用 Pandas 计算每个组的唯一值

python - 机器人测试接收到的 unicode 与从 python 关键字发送的不同

c++ - 没有找到 Qt Creator 3.2.0 的 qmake.exe

c++ - C++ 中 QObject 多重继承和策略/特征设计的问题

python - 如何在 PyQt 中设置大于屏幕 2/3 的小部件的初始大小

python - PyQt4 到 PyQt5 -> mainFrame() 已弃用,需要修复才能加载网页

python - 延迟加载字典

c++ - 模型 View 困难

Python QWebEngineView 重定向到错误的语言页面

python - PyQt5 :How to communicate between two subwindows?