How do I create a custom slot in qt4 designer?

2020-02-08 12:20发布

Whenever I use the signal/slot editor dialog box, I have to choose from the existing list of slots. So the question is how do I create a custom named slot?

10条回答
趁早两清
2楼-- · 2020-02-08 13:03

This does seem to be possible in the version of Qt Designer 4.5.2, but it can't be done from the Signal/Slot Editor dock-widget in the main window.

This is what worked for me

  1. Switch to Edit Signals/Slots mode (F4)
  2. Drag and drop from the widget which is to emit the signal, to the widget which is to receive the signal.
  3. A Configure Connection dialog appears, showing the signals for the emitting widget, and the slots for the receiving widget. Click Edit... below the slots column on the right.
  4. A Signals/Slots of ReceivingWidget dialog appears. In here its is possible to click the plus icon beneath slots to add a new slot of any name.
  5. You can then go back and connect to your new slot in the Configure Connection dialog, or indeed in the Signal/Slot Editor dockwidget back in the main window.

Caveat: I'm using PyQt, and I've only tried to use slots added in this way from Python, not from C++, so your mileage may vary...

查看更多
淡お忘
3楼-- · 2020-02-08 13:09

Maybe it'll help.

By default you have to choose from the existing list of slots. But you can add slot by right-clicking at you object in the list at right side of designer and choose "slot/signals" and add your custom slot/signal. After that, you can choose it in signal/slot editor.

查看更多
甜甜的少女心
4楼-- · 2020-02-08 13:12

It is not possible to do it, because it means you would add a slot to an existing Qt class like QPushButton which is not really the way to go.

You should create your own QWidget eventually by subclassing an existing one. Then integrating it into Qt Designer as a plugin as suggested. Having your own class allows you to add/modifiy the signals/slots available as you want.

查看更多
冷血范
5楼-- · 2020-02-08 13:14

click the widget by right button

promote the widget into a class you defined

click the widget by right button again

you will see that signal and slot is editable

查看更多
登录 后发表回答