How do I create a custom slot in qt4 designer?

前端 未结 10 563
我在风中等你
我在风中等你 2020-12-14 18:29

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条回答
  • 2020-12-14 18:53

    Don't forget about the slot auto-connection features. There are a few drawbacks, like having to rename your function if you rename your widget, but we use those a lot at my company.

    0 讨论(0)
  • 2020-12-14 18:56

    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...

    0 讨论(0)
  • 2020-12-14 18:59

    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

    0 讨论(0)
  • 2020-12-14 19:04

    This doesn't seem to be possible in a simple way.

    The designer only allows you to promote existing widgets to your own custom widgets. yet it doesn't allow you to connect the signals and slots of the class of promoted widgets.

    The way this is possible is creating a plugin for the designer as is described here and in the pages that follow it.

    The normal course of action is to promote a widget to your own class and then to connect it manually in your own code. this process is described here

    0 讨论(0)
提交回复
热议问题