Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5a1471f

Browse files
8927689276
89276
authored and
89276
committed
嵌入外部窗口
1 parent 80fb7ef commit 5a1471f

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [1.20 exec()动态生成控件](partner_625781186/1.exec动态生成控件/)
2828
- [1.21 仿QQ设置面板](仿QQ设置面板/)
2929
- [1.22 Json生成QTreeWidget](Json生成QTreeWidget/)
30+
- [1.23 嵌入外部窗口](嵌入外部窗口/)
3031

3132

3233
### [2.QGraphicsView练习](QGraphicsView练习/)

‎嵌入外部窗口/EmbedWidget.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,30 @@ def onItemDoubleClicked(self, item):
4444
# 如果数量等于4说明之前已经嵌入了一个窗口,现在需要把它释放出来
4545
self.restore()
4646
hwnd, phwnd = int(hwnd), int(phwnd)
47+
# 嵌入之前的属性
48+
style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)
49+
exstyle = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
50+
print('save', hwnd, style, exstyle)
51+
4752
widget = QWidget.createWindowContainer(QWindow.fromWinId(hwnd))
4853
widget.hwnd = hwnd # 窗口句柄
4954
widget.phwnd = phwnd # 父窗口句柄
50-
widget.style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE) # 窗口样式
51-
widget.exstyle = win32gui.GetWindowLong(
52-
hwnd, win32con.GWL_EXSTYLE) # 窗口额外样式
55+
widget.style = style # 窗口样式
56+
widget.exstyle = exstyle # 窗口额外样式
5357
self.layout().addWidget(widget)
5458

5559
def restore(self):
5660
"""归还窗口"""
61+
# 有bug,归还后窗口没有了WS_VISIBLE样式,不可见
5762
widget = self.layout().itemAt(3).widget()
63+
print('restore', widget.hwnd, widget.style, widget.exstyle)
5864
win32gui.SetParent(widget.hwnd, widget.phwnd) # 让它返回它的父窗口
5965
win32gui.SetWindowLong(
60-
widget.hwnd, win32con.GWL_STYLE, widget.style) # 恢复样式
66+
widget.hwnd, win32con.GWL_STYLE, widget.style|win32con.WS_VISIBLE) # 恢复样式
6167
win32gui.SetWindowLong(
6268
widget.hwnd, win32con.GWL_EXSTYLE, widget.exstyle) # 恢复样式
63-
win32gui.ShowWindow(widget.hwnd, win32con.SW_SHOW) # 显示窗口OF
69+
win32gui.ShowWindow(
70+
widget.hwnd, win32con.SW_SHOW) # 显示窗口
6471
widget.close()
6572
self.layout().removeWidget(widget) # 从布局中移出
6673
widget.deleteLater()

‎嵌入外部窗口/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 内嵌外部窗口
2+
3+
### 原理思路:
4+
- 1.使用SetParent函数设置外部窗口的parent为Qt的窗口
5+
- 2.Qt使用QWidget.createWindowContainer(QWindow.fromWinId(窗口ID))生成QWidget
6+
- 3.使用GetWindowLong得到原来窗口的样式属性(style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)和exstyle = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE))
7+
- 4.这里还原窗口后不会显示,用spy++发现没有了WS_VISIBLE样式(未解决)
8+
9+
[Issues#3](https://github.com/892768447/PyQt/issues/3)
10+
11+
截图
12+
13+
![1](ScreenShot/1.gif)

‎嵌入外部窗口/ScreenShot/1.gif‎

344 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /