Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Does Qt not have a switch widgets?
Forum Updated to NodeBB v4.3 + New Features

Does Qt not have a switch widgets?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Publicnamer
    wrote on 31 Oct 2021, 03:44 last edited by Publicnamer
    #1

    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.

    E 1 Reply Last reply 31 Oct 2021, 03:54
    0
    • P Publicnamer
      31 Oct 2021, 03:44

      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.

      E Offline
      E Offline
      eyllanesc
      wrote on 31 Oct 2021, 03:54 last edited by
      #2

      @Publicnamer

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

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on 31 Oct 2021, 06:01 last edited by
        #3

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

        P 1 Reply Last reply 1 Nov 2021, 03:05
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 31 Oct 2021, 20:02 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply 1 Nov 2021, 03:03
          1
          • S SGaist
            31 Oct 2021, 20:02

            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.

            P Offline
            P Offline
            Publicnamer
            wrote on 1 Nov 2021, 03:03 last edited by
            #5

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

            J 1 Reply Last reply 2 Nov 2021, 07:19
            0
            • C ChrisW67
              31 Oct 2021, 06:01

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

              P Offline
              P Offline
              Publicnamer
              wrote on 1 Nov 2021, 03:05 last edited by
              #6

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

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on 1 Nov 2021, 04:30 last edited by
                #7

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

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

                1 Reply Last reply
                1
                • P Publicnamer
                  1 Nov 2021, 03:03

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

                  J Online
                  J Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on 2 Nov 2021, 07:19 last edited by
                  #8

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

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  1/8

                  31 Oct 2021, 03:44

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved