how to show LED in GUI and use push button to control it
-
@mrjj said in how to show LED in GUI and use push button to control it:
@rezaMSLM
the background-color controls that.
you can do
background-color: rgb(47, 255, 11);
to set a color using RGBthat controls all buttons color
i want some red, some green and so on -
@rezaMSLM
You can use names.
this is a MUST read.
https://doc.qt.io/Qt-5/stylesheet-syntax.htmlQRadioButton#Name::indicator xxxxx
but i think the other leds you found will work better for this that style sheet. but
it should be doable. -
i use this code:
void MainWindow::on_checkBox1_clicked(bool checked) { if(checked == true) { ui->radioButton_2->show(); QString StyleSheetOn("QRadioButton::mainwindow {width: 25px; height: 25px; border-radius: 7px;} QRadioButton#radioButton_2::indicator:unchecked { background-color: lime; border: 2px solid gray;}"); setStyleSheet(StyleSheetOn); } else { ui->radioButton_2->hide(); } } void MainWindow::on_checkBox2_clicked(bool checked) { if(checked == true) { ui->radioButton->show(); QString StyleSheetOn2("QRadioButton::mainwindow {width: 25px; height: 25px; border-radius: 7px;} QRadioButton#radioButton::indicator:unchecked { background-color: red; border: 2px solid gray;}"); setStyleSheet(StyleSheetOn2); } else { ui->radioButton->hide(); } }
here is the result:
when showing one LED the other one is affected!
-
@rezaMSLM
well i imagined you defined a big style sheet with
the names of all the LED
and set it once.
then hide() /show themyou can set stylesheet on mainwindow and it affects them also
no need to do directly on radiobutton. -
@rezaMSLM
Ok
There is no need to set stylesheet on radio buttons.
If you right click main window and select Change stylesheet
you can put all lines there
QRadioButton#radioButton_2::xxx
QRadioButton#radioButton_3::xxx
QRadioButton#radioButton_4::xxxfor the colors u want.
all of it. for all names. and the default one.
then its always in effect.
and then just
ui->radioButton->show()/hide()how many leds will there be ?
-
@rezaMSLM
well its possible to do more generic.
sender()) or lambdaits just a widget like radio button so its almost the same.
however, there is no designer version so you have to new it and place it.
(or use promotion as i did )those leds will be fixed ?
So you have no need to save and load the locations? -
@rezaMSLM
ok so it will work pretty fine just placing them in designer.in the sample
https://www.dropbox.com/s/qi7frrlyvnrjvy6/LedTest.zip?dl=0i use promotion. that allows you to copy them around and at run time they be the leds.
did u try sample?
-
@mrjj
I still don't understand how to put LED's on different places on the map@mrjj said in how to show LED in GUI and use push button to control it:
i use promotion. that allows you to copy them around and at run time they be the leds.
please explain more.
how to use promotion? -
@rezaMSLM
you put a widget on the form and right click it
select Promote
then give it the class name and include
Then click Add
and then promote.
When run, its now a Led.
you must have ledIndicator.cpp and .h added to projectalso explained here
http://doc.qt.io/qt-5/designer-using-custom-widgets.html