how to show LED in GUI and use push button to control it
-
to work with led i use this example:
https://github.com/melanholly/qt5-led-indicator-widgetbut my first problem is how to load my image(the map) in GUI.
i have tried this way:
added a label to gui and choose pixmap in Qlabel menu and browsed to the image.(is this a good way?)
now my problem is that dont know how to put LED's on image in places that I want
can anyone help me? -
@rezaMSLM
No its not a good way as its not an image :)
Its a widgets and you can either new a object and insert as website shows Or use
promotion to add it to form.
http://doc.qt.io/qt-5/designer-using-custom-widgets.htmlSo have the ledindicator.h / ledindicator.cpp in same folder as main project.
open mainwindow.ui
place a QWidget on the form
Right click the widget
choose promote
fill in the class name and .h filename
press Add
Then pres promote
run app -
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...)