I want to use btn1 to send a signal to the slot function of deviceTypeSelect, but btn1 can only be associated with QStackedWidget.

- 150
- 9
-
what *slot function*? – eyllanesc Dec 03 '20 at 07:55
-
The custom slot method in deviceTypeSelect, I will promote deviceTypeSelect. – Alex Dec 03 '20 at 08:14
-
You are going to do it but you haven't, that's why you can't find that slot in Qt Designer. Please provide a [mre] – eyllanesc Dec 03 '20 at 08:18
-
Only the predefined slots of *existing* classes can be used. Qt Designer cannot know what slots are going to be in a widget that **will** be promoted, how could it?! – musicamante Dec 03 '20 at 08:19
-
I did promoted and the result is still the same.This demo is not easy to describe with code, but pictures are better. – Alex Dec 03 '20 at 08:27
-
@Alex: the slots are defined in the python class that is going to be used as the promoted widget, right? – musicamante Dec 03 '20 at 08:35
-
The key is why the subpage of QStackedWidget can't accept signal? – Alex Dec 03 '20 at 08:36
-
@musicamante yeah, That's it what I want. – Alex Dec 03 '20 at 08:40
1 Answers
There are two problems.
The first is conceptual: Designer cannot know anything about custom slots that are going to be implemented in a promoted widget, and it even should not. The connection to those slots can only be achieved programmatically, and that's for good reasons: Designer cannot "inspect" (nor it should) the source of the files that will be promoted, and it's also completely possible that one would promote a widget and use different classes with the same design files.
The other problem is technical: the "pages" of multipage widgets like QStackedWidget or QTabWidget cannot be used as signal targets on Designer. I don't know if it's just a missing feature or it's by design (knowing how multipage widget plugins are dealt with I wouldn't bet about the it), but unfortunately it really is not possible.
If you want to connect to standard QWidget slots (setEnabled()
etc.), set a dummy boxed layout on the page, and add another QWidget in it, but if you use custom slots, as explained before, those must be manually connected from your code.

- 41,230
- 6
- 33
- 58
-
Thanks for comment ,So I can only promote QStackedWidget, and then customize the slot in it to associate the signal of btn1. – Alex Dec 03 '20 at 09:22
-
That's up to you, but since custom slots can only be connected programmatically there's no much difference, it just depends on what that slot is going to do: if it does something on *that page* only, promoting the page will suffice, but if its interaction is in the common scope of the stacked widget, promote that one instead. – musicamante Dec 03 '20 at 09:32