如何检查 QWidget 是否已经显示?

发布于 2024-09-25 20:58:10 字数 165 浏览 2 评论 0原文

我正在使用 PyQt4 为现有应用程序开发插件 UI。该窗口是通过按下主窗口中的按钮使用 uic.loadUi() 创建的。问题是,如果我再次按下按钮(当窗口显示时),窗口将重新创建,未保存的更改将丢失。我不想让窗口成为​​模态窗口。我必须采取哪些选择来解决这个问题?我想这与检查 QWidget 是否已经显示有关。

I'm developing a plugin UI for an existing application using PyQt4. The window is created using uic.loadUi() on the press of a button in the main window. The problem is that if I press the button again (while the window is showing) the window is re-created and unsaved changes are lost. I don't want to make the window modal. Which options do I have to cope with this problem? I guess it would be related to checking whether the QWidget is already showing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫南 2024-10-02 20:58:10

您应该将指向 QWidget(成员变量)的指针初始化为 0。

按下按钮时,检查指针是否为 0 - 如果是,则加载并显示该小部件,并将指针变量分配为指向新的小部件。如果按下按钮时指针不为空,则调用 widget->raise()widget->activateWindow()

禁用的按钮可能会让用户感到沮丧,因为按钮的效果被隐藏了,所以看起来什么也不做。

You should initializer a pointer to the QWidget (member variable) to 0.

When the button is pressed, check if the pointer is 0 - if it is, load and show the widget, and assign the pointer variable to point to the new widget. If the pointer is not null when the button is pressed, call widget->raise() and widget->activateWindow().

Disabled buttons can be frustrating to users, as can buttons which appear to do nothing because e.g. their effect is hidden.

〆一缕阳光ご 2024-10-02 20:58:10

我本以为这将更多地由您的应用程序逻辑来处理,而不是其他任何事情。主窗口应在单击按钮后禁用该按钮,然后在窗口关闭时再次重新启用它。将辅助窗口上的关闭信号连接到主窗口上的插槽,以在辅助窗口关闭时通知主窗口。

I would have thought that this would be handled more by your application logic than anything else. The main window should disable the button after it has been clicked and then re-enable it again when the window is closed. Connect up a closing signal on the secondary window to a slot on the main window to notify the main window when the secondary window is being closed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文