PyQt QTreeWidget“扩展”信号未被捕获
我刚刚开始为 Qt 应用程序维护一组嵌入式 Python 插件。我对 PyQt 和 Python 都很陌生,所以请耐心等待。
我在一个对话框中有一个 QTreeWidget 的实现,其中“扩展”信号没有被相应的处理程序捕获。我有另一个对话框,它工作得很好。
在问题对话框中,我可以验证连接是否成功。
connected = wdg.connect(wdg.treeView_,SIGNAL("expanded(QTreeViewItem*)"), wdg.expanded)
评估结果为 True。当我单击子指示器展开项目时,[+] 符号变为减号,但没有其他反应。同样,当我单击 [-] 时,它会切换回 [+]。我已将 ChildIndicatorPolicy 设置为在这两种情况下最初将指示器设置为 SHOW。
在运行正常的对话框中,当用户单击加号时,将执行“展开”处理程序。只有单击指示器时才会切换。
我的处理程序代码很简单:
def expanded(self, item):
logging.debug("In expanded handler")
我在日志记录调用处有一个断点,但从未到达该语句。
在失败的对话框中,我有另一个信号在上面的信号之前立即连接,并且它工作得很好:
wdg.connect(wdg.treeView_,SIGNAL("currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)"), wdg.itemChanged)
是否有什么可以阻止扩展信号发射或被捕获?也许是另一件事?我应该寻找什么?我意识到我的命名可能有点偏差,我也欢迎在这方面的任何修正。
I just started maintaining a set of embedded Python plugins for a Qt application. I'm also new to both PyQt and Python, so bear with me.
I have an implementation of a QTreeWidget in one dialog where the "expanded" signal is not being caught by the corresponding handler. I have another dialog where it works just fine.
In the problem dialog, I can verify that the connect was successful.
connected = wdg.connect(wdg.treeView_,SIGNAL("expanded(QTreeViewItem*)"), wdg.expanded)
evaluates to True. When I click on the child indicators to expand an item, the [+] signs change to a minus, but nothing else happens. Likewise, when I click on the [-], it toggles back to [+]. I have set the ChildIndicatorPolicy to initially set the indicator to SHOW in both cases.
In the dialog that works OK, when the user clicks on the plus sign, the 'expanded' handler is executed. Only the indicator toggles when it is clicked.
My handler code is simply:
def expanded(self, item):
logging.debug("In expanded handler")
I have a breakpoint at the logging call, but the statement is never reached.
I the failing dialog, I have another signal that's connected immediately before the one above, and it works just fine:
wdg.connect(wdg.treeView_,SIGNAL("currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)"), wdg.itemChanged)
Is there anything that could prevent an expanded signal from firing or being caught? Another event perhaps? What should I be looking for? I realize that my nomenclature may be a bit off, and I welcome any correction in that regard as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了问题。尽管名称具有误导性,但该对象是一个 QTreeWidge。当我将信号名称从
"expanded"
替换为"itemExpanded"
并将参数类型更改为QTreeWidgetItem*
时,一切正常。I found the problem. Despite the misleading name, the object is a
QTreeWidge
. When I replaced the name of the signal from"expanded"
to"itemExpanded"
and changed the parameter type to aQTreeWidgetItem*
, everything worked.QTreeView 扩展事件的信号是 "expanded(QModelIndex) ”。
或者,考虑使用新样式信号/槽语法 。我发现这比查找特定信号的确切参数类型容易得多。
The signal for a QTreeView expansion event is "expanded(QModelIndex)".
Alternatively, consider using the new style signal/slot syntax. I find it much easier than looking up the exact argument type for a particular signal.