how to show LED in GUI and use push button to control it
-
hi
i assume you try to use in your project.
here is sample using it
https://www.dropbox.com/s/qi7frrlyvnrjvy6/LedTest.zip?dl=0
(with promotion as i talked about) -
@rezaMSLM said in how to show LED in GUI and use push button to control it:
how to add my map to the GUI?
Do you mean setting a background image for the MainWindow? If so, see example
-
@Pablo-J.-Rogina said in how to show LED in GUI and use push button to control it:
@rezaMSLM said in how to show LED in GUI and use push button to control it:
how to add my map to the GUI?
Do you mean setting a background image for the MainWindow? If so, see example
yes thank you!
but the image is tile:
how to correct it?
i want something like this:
-
I made these with radio buttons.
I use setStyleSheet method and sent these strings:
/QString StyleSheetOn("QRadioButton::indicator {width: 15px; height: 15px; border-radius: 7px;} QRadioButton::indicator:unchecked { background-color: lime; border: 2px solid gray;}"); QString StyleSheetOff("QRadioButton::indicator {width: 15px; height: 15px; border-radius: 7px;} QRadioButton::indicator:unchecked { background-color: black; border: 2px solid gray;}");
I dont set check i simply set style sheet, I suppose you could set stylesheets for checked and unchecked and use setChecked methods.
-Shawn
-
@MrShawn said in how to show LED in GUI and use push button to control it:
I made these with radio buttons.
I use setStyleSheet method and sent these strings:
/QString StyleSheetOn("QRadioButton::indicator {width: 15px; height: 15px; border-radius: 7px;} QRadioButton::indicator:unchecked { background-color: lime; border: 2px solid gray;}"); QString StyleSheetOff("QRadioButton::indicator {width: 15px; height: 15px; border-radius: 7px;} QRadioButton::indicator:unchecked { background-color: black; border: 2px solid gray;}");
I dont set check i simply set style sheet, I suppose you could set stylesheets for checked and unchecked and use setChecked methods.
-Shawn
thanks
a good solution
but i have a problem!
when i put the radio button on a location on the map and run the program, thats fine but if i maximize the window, the map gets larger and so locations will move but radio buttons remain in previous locations. i want radiobuttons to move with map in order to remain on the location.
before window maximize:
After maximize:
EDIT:
i have used Qframe and set map as backgroundl to load the map in GUI -
@mrjj said in how to show LED in GUI and use push button to control it:
@rezaMSLM
Make sure the radiobuttons are childs of the frame
thanks, worked!
another question:
i used this command to full screen the main window:
resize(QDesktopWidget().availableGeometry(this).size());how to make the frame(map) the same size of the main window?
-
@jsulm said in how to show LED in GUI and use push button to control it:
@rezaMSLM If you use layouts then it should resize automatically
i use many radio buttons in different locations in the frame, if use layouts i can not put radio buttons any location that i want. in addition when resizing the main window the radio buttons move more than map locations and get moved to a wrong location.
-
@MrShawn said in how to show LED in GUI and use push button to control it:
I made these with radio buttons.
I use setStyleSheet method and sent these strings:
/QString StyleSheetOn("QRadioButton::indicator {width: 15px; height: 15px; border-radius: 7px;} QRadioButton::indicator:unchecked { background-color: lime; border: 2px solid gray;}"); QString StyleSheetOff("QRadioButton::indicator {width: 15px; height: 15px; border-radius: 7px;} QRadioButton::indicator:unchecked { background-color: black; border: 2px solid gray;}");
I dont set check i simply set style sheet, I suppose you could set stylesheets for checked and unchecked and use setChecked methods.
-Shawn
if i want to set radio buttons colors to different colors how to change the code?
(i want some green radiobuttons some red etc...) -
@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.