Does Qt not have a switch widgets?
-
wrote on 31 Oct 2021, 03:44 last edited by Publicnamer
I need either a switch widget i.e. a sliding on-off button like the UISwitch on iOS,
or perhaps a segmented control i.e. you press one of n words to choose between multiple options.
Does such a thing not exist in Qt? I see on stackoverflow people showing code to implement a SwitchButton from scratch. -
I need either a switch widget i.e. a sliding on-off button like the UISwitch on iOS,
or perhaps a segmented control i.e. you press one of n words to choose between multiple options.
Does such a thing not exist in Qt? I see on stackoverflow people showing code to implement a SwitchButton from scratch.wrote on 31 Oct 2021, 03:54 last edited byThere is no QWidget that is a switch, the closest thing would be a QRadioButton. Another option is that you inherit from QAbstractButton and implement custom painting. Another possibility is to use the switch component of QML: https://doc.qt.io/Qt-5/qml-qtquick-controls2-switch.html
On the other hand for your second requirement you could use a set of buttons (maybe qcheckbox or qradiobuttons) and manage their activation through QButtonGroup, the same logic can be implemented with QML.
-
wrote on 31 Oct 2021, 06:01 last edited by
@Publicnamer said in Does Qt not have a switch widgets?:
I need either a switch widget i.e. a sliding on-off button like the UISwitch on iOS,
If it has to look like the IOS widget then, no, there is no such item out of the box.
As SO no doubt mentioned, QPushButton with PushButton::setCheckable(bool) gives you equivalent functionality. QCheckBox is the other obvious equivalent.or perhaps a segmented control i.e. you press one of n words to choose between multiple options.
That is a group of radio buttons or a QComboBox
Does such a thing not exist in Qt?
Equivalent functionality exists in Qt.
I see on stackoverflow people showing code to implement a SwitchButton from scratch.
If you must make every platform look like it is a phone then you will have to implement painting the widget yourself. A customised QPushButton/QCheckBox could render like the IOS widget, or you could go the route of a complete button implementation as in SO answer here (and probably elsewhere)
If you are writing to target mobile devices then you should consider QML.
-
Hi,
You might want to check the Maui Kit project which is built on top KDE and Qt to provide controls for mobile as well as desktop.
-
Hi,
You might want to check the Maui Kit project which is built on top KDE and Qt to provide controls for mobile as well as desktop.
wrote on 1 Nov 2021, 03:03 last edited by@SGaist said in Does Qt not have a switch widgets?:
Maui Kit project
I'm trying to avoid adding layers of bloat, lest the software become too slow to be usable. The software I'm writing may run on very slow devices. For instance the original PinePhone which is half as fast as the latest Raspberry pi.
-
@Publicnamer said in Does Qt not have a switch widgets?:
I need either a switch widget i.e. a sliding on-off button like the UISwitch on iOS,
If it has to look like the IOS widget then, no, there is no such item out of the box.
As SO no doubt mentioned, QPushButton with PushButton::setCheckable(bool) gives you equivalent functionality. QCheckBox is the other obvious equivalent.or perhaps a segmented control i.e. you press one of n words to choose between multiple options.
That is a group of radio buttons or a QComboBox
Does such a thing not exist in Qt?
Equivalent functionality exists in Qt.
I see on stackoverflow people showing code to implement a SwitchButton from scratch.
If you must make every platform look like it is a phone then you will have to implement painting the widget yourself. A customised QPushButton/QCheckBox could render like the IOS widget, or you could go the route of a complete button implementation as in SO answer here (and probably elsewhere)
If you are writing to target mobile devices then you should consider QML.
wrote on 1 Nov 2021, 03:05 last edited by@ChrisW67 said in Does Qt not have a switch widgets?:
If you are writing to target mobile devices then you should consider QML.
Oh really? Why? I don't see any reason to.
-
wrote on 1 Nov 2021, 04:30 last edited by
@Publicnamer said in Does Qt not have a switch widgets?:
Oh really?
Uh huh. @eyllanesc seems to think so too.
Why?
Possibly because you would find an example of the type switch UI element you seek in a QML example that comes with Qt. There may even be what you are referring to as a "segmented control," but I am not entirely certain what that is supposed to look like.
https://doc.qt.io/qt-5/qtquickcontrols-imagine-automotive-example.htmlThen you may find that QML works better for a variable geometry like you see on mobile devices.
I don't see any reason to.
That's your prerogative. You cannot make informed choices if you do not consider options.
-
@SGaist said in Does Qt not have a switch widgets?:
Maui Kit project
I'm trying to avoid adding layers of bloat, lest the software become too slow to be usable. The software I'm writing may run on very slow devices. For instance the original PinePhone which is half as fast as the latest Raspberry pi.
@Publicnamer said in Does Qt not have a switch widgets?:
I'm trying to avoid adding layers of bloat
You don't have to add it, but you can check how they implemented this control...
1/8