如何在不创建派生类的情况下模拟 QTreeWidget itemClicked 信号?
我无法找到 QTreeWidget 的 ItemClicked() SIGNAL 的正确模拟。
有没有办法模拟它以便生成 ItemClicked 信号?
例如:我们可以在 QTreeWidget 的派生类中发出 ItemClicked,但不能(作为 QT 规则)在它之外。
I am unable to find a proper simulation for ItemClicked() SIGNAL for QTreeWidget.
Is there a way to simulate it so that ItemClicked Signal is generated ?
e.g: we can emit ItemClicked in a derived class of QTreeWidget but cannot (as a QT rule) outside of it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用 A 类的
emit
调用来发出 B 类的信号。但请注意信号和槽的文档 说:“您可以将任意数量的信号连接到单个插槽,并且一个信号可以连接到您需要的任意数量的插槽。甚至可以将一个信号直接连接到另一个信号。(这将发出每当第一个信号发出时,立即发出第二个信号。)”
因此,您可以通过在 A 类中声明一个与您希望 B 类发出的信号具有相同签名的信号来解决此问题,并将这些信号连接在一起:
然后发出itemClicked 来自
myclass
。如果我没有记错的话,它适用于这种情况......并为您触发树形小部件的 itemClicked 信号。You can't use the
emit
call for class A to emit class B's signals. But note that the documentation for signals and slots says:"You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need. It is even possible to connect a signal directly to another signal. (This will emit the second signal immediately whenever the first is emitted.)"
So you can work around this by declaring a signal in class A of the same signature as the one you want class B to emit, and connecting the signals together:
Then emit itemClicked from
myclass
. If I'm not mistaken, it will work for this case...and fire the treewidget's itemClicked signal for you.