Best way to implement a toggle button with Qt [duplicate]
Asked Answered
D

1

5

What is the best way to implement a toggle button with the Qt framework ?

EDIT:

The only possibility I am aware of is the QPushButton. According to Qt documentation the QPushButton::setCheckable(bool) allows to have a on/off behavior. How to make it appear such as below ? Knowing I use Qt 5.1.1

enter image description here

Defelice answered 4/5, 2018 at 13:19 Comment(6)
Maybe QPushButton::setCheckable(bool) property makes it toggle?Bipartite
doc.qt.io/qt-5/qpushbutton.html - search for "toggle" in the pageHudis
If I use such a function, how can I make my ToggleButton appear such as a toggle button ? knowing that I use Qt 5.1.1Defelice
The simplest way is to use an image. Put one for pressed and one of released.Prey
You can set background/border images to it using stylesheets. See pseudo states for stylesheets.Verney
If you want to make the button feel like on iOS. See this https://mcmap.net/q/403422/-toggle-switch-in-qt - it involves many lines of codes and anmiation.Prey
M
7

I'm not sure for QPushButton, but for QCheckboxes, you can set an icon as a stylesheet, meaning that you can give any appearance you want to your checkbox. So your "on" image could be the icon for state "checked" and your "off" image for state "unchecked" (http://doc.qt.io/archives/qt-4.8/stylesheet-examples.html#customizing-qcheckbox)

Mend answered 4/5, 2018 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.