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. how to show LED in GUI and use push button to control it
Forum Updated to NodeBB v4.3 + New Features

how to show LED in GUI and use push button to control it

Scheduled Pinned Locked Moved Unsolved General and Desktop
37 Posts 6 Posters 17.5k Views 2 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.
  • R Offline
    R Offline
    rezaMSLM
    wrote on 5 Jul 2018, 13:39 last edited by
    #1

    hello
    i want to load a map(or Image) in my gui and put some LEDs on it and use push button to control them.
    how can i do this?

    K 1 Reply Last reply 5 Jul 2018, 14:10
    0
    • R rezaMSLM
      5 Jul 2018, 13:39

      hello
      i want to load a map(or Image) in my gui and put some LEDs on it and use push button to control them.
      how can i do this?

      K Offline
      K Offline
      koahnig
      wrote on 5 Jul 2018, 14:10 last edited by
      #2

      @rezaMSLM

      You can have a look to QLedIndicator. It probably has teh functionality as you require.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      4
      • R Offline
        R Offline
        rezaMSLM
        wrote on 16 Jul 2018, 15:31 last edited by rezaMSLM
        #3

        to work with led i use this example:
        https://github.com/melanholly/qt5-led-indicator-widget

        but 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?

        M 1 Reply Last reply 16 Jul 2018, 15:48
        0
        • R rezaMSLM
          16 Jul 2018, 15:31

          to work with led i use this example:
          https://github.com/melanholly/qt5-led-indicator-widget

          but 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?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 16 Jul 2018, 15:48 last edited by
          #4

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

          So 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

          alt text

          1 Reply Last reply
          1
          • R Offline
            R Offline
            rezaMSLM
            wrote on 16 Jul 2018, 16:19 last edited by
            #5

            0_1531799274463_Capture.JPG

            i put classname and .h filename "ledindicator" but error occured

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 16 Jul 2018, 16:26 last edited by mrjj
              #6

              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)

              R 1 Reply Last reply 16 Jul 2018, 16:34
              0
              • M mrjj
                16 Jul 2018, 16:26

                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)

                R Offline
                R Offline
                rezaMSLM
                wrote on 16 Jul 2018, 16:34 last edited by
                #7

                @mrjj said in how to show LED in GUI and use push button to control it:

                i assume you try to use in your project.

                that's right!
                thank you i ran it but what next?

                M 1 Reply Last reply 16 Jul 2018, 16:39
                0
                • R rezaMSLM
                  16 Jul 2018, 16:34

                  @mrjj said in how to show LED in GUI and use push button to control it:

                  i assume you try to use in your project.

                  that's right!
                  thank you i ran it but what next?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 16 Jul 2018, 16:39 last edited by
                  #8

                  @rezaMSLM
                  download project. run it ?
                  study .pro file

                  R 1 Reply Last reply 16 Jul 2018, 17:16
                  0
                  • M mrjj
                    16 Jul 2018, 16:39

                    @rezaMSLM
                    download project. run it ?
                    study .pro file

                    R Offline
                    R Offline
                    rezaMSLM
                    wrote on 16 Jul 2018, 17:16 last edited by
                    #9

                    @mrjj said in how to show LED in GUI and use push button to control it:

                    download project. run it ?
                    yes

                    my question is remaining
                    how to add my map to the GUI?

                    Pablo J. RoginaP 1 Reply Last reply 16 Jul 2018, 17:29
                    0
                    • R rezaMSLM
                      16 Jul 2018, 17:16

                      @mrjj said in how to show LED in GUI and use push button to control it:

                      download project. run it ?
                      yes

                      my question is remaining
                      how to add my map to the GUI?

                      Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on 16 Jul 2018, 17:29 last edited by
                      #10

                      @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

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      R 1 Reply Last reply 16 Jul 2018, 17:45
                      2
                      • Pablo J. RoginaP Pablo J. Rogina
                        16 Jul 2018, 17:29

                        @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

                        R Offline
                        R Offline
                        rezaMSLM
                        wrote on 16 Jul 2018, 17:45 last edited by
                        #11

                        @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:
                        0_1531804455779_333.JPG

                        how to correct it?

                        i want something like this:
                        0_1531804489001_77.jpg

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          MrShawn
                          wrote on 16 Jul 2018, 20:55 last edited by
                          #12

                          I made these with radio buttons.

                          0_1531774374555_513fe1d2-f658-4af1-acfa-9a04da38b7a4-image.png

                          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

                          R 2 Replies Last reply 17 Jul 2018, 04:04
                          1
                          • M MrShawn
                            16 Jul 2018, 20:55

                            I made these with radio buttons.

                            0_1531774374555_513fe1d2-f658-4af1-acfa-9a04da38b7a4-image.png

                            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

                            R Offline
                            R Offline
                            rezaMSLM
                            wrote on 17 Jul 2018, 04:04 last edited by rezaMSLM
                            #13

                            @MrShawn said in how to show LED in GUI and use push button to control it:

                            I made these with radio buttons.

                            0_1531774374555_513fe1d2-f658-4af1-acfa-9a04da38b7a4-image.png

                            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:
                            0_1531841532556_456.JPG

                            After maximize:
                            0_1531841582839_4561.JPG

                            EDIT:
                            i have used Qframe and set map as backgroundl to load the map in GUI

                            M 1 Reply Last reply 17 Jul 2018, 10:04
                            0
                            • R rezaMSLM
                              17 Jul 2018, 04:04

                              @MrShawn said in how to show LED in GUI and use push button to control it:

                              I made these with radio buttons.

                              0_1531774374555_513fe1d2-f658-4af1-acfa-9a04da38b7a4-image.png

                              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:
                              0_1531841532556_456.JPG

                              After maximize:
                              0_1531841582839_4561.JPG

                              EDIT:
                              i have used Qframe and set map as backgroundl to load the map in GUI

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 17 Jul 2018, 10:04 last edited by
                              #14

                              @rezaMSLM
                              Make sure the radiobuttons are childs of the frame
                              alt text

                              R 1 Reply Last reply 18 Jul 2018, 07:13
                              1
                              • M mrjj
                                17 Jul 2018, 10:04

                                @rezaMSLM
                                Make sure the radiobuttons are childs of the frame
                                alt text

                                R Offline
                                R Offline
                                rezaMSLM
                                wrote on 18 Jul 2018, 07:13 last edited by
                                #15

                                @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
                                alt text

                                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?

                                jsulmJ 1 Reply Last reply 18 Jul 2018, 07:37
                                0
                                • R rezaMSLM
                                  18 Jul 2018, 07:13

                                  @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
                                  alt text

                                  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?

                                  jsulmJ Online
                                  jsulmJ Online
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 18 Jul 2018, 07:37 last edited by
                                  #16

                                  @rezaMSLM If you use layouts then it should resize automatically

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

                                  R 1 Reply Last reply 18 Jul 2018, 07:57
                                  1
                                  • jsulmJ jsulm
                                    18 Jul 2018, 07:37

                                    @rezaMSLM If you use layouts then it should resize automatically

                                    R Offline
                                    R Offline
                                    rezaMSLM
                                    wrote on 18 Jul 2018, 07:57 last edited by
                                    #17

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

                                    1 Reply Last reply
                                    0
                                    • R Offline
                                      R Offline
                                      rezaMSLM
                                      wrote on 18 Jul 2018, 08:01 last edited by
                                      #18

                                      the answer that solves my problem is that "how to set frame size to the size of main window without using layouts"

                                      1 Reply Last reply
                                      0
                                      • R Offline
                                        R Offline
                                        rezaMSLM
                                        wrote on 18 Jul 2018, 11:24 last edited by rezaMSLM
                                        #19

                                        if i use layouts this happens:
                                        alt text

                                        you see that when resizing the window, the radio button is not attached to the map

                                        0_1531954592656_3333.JPG

                                        1 Reply Last reply
                                        0
                                        • M MrShawn
                                          16 Jul 2018, 20:55

                                          I made these with radio buttons.

                                          0_1531774374555_513fe1d2-f658-4af1-acfa-9a04da38b7a4-image.png

                                          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

                                          R Offline
                                          R Offline
                                          rezaMSLM
                                          wrote on 20 Jul 2018, 10:34 last edited by
                                          #20

                                          @MrShawn said in how to show LED in GUI and use push button to control it:

                                          I made these with radio buttons.

                                          0_1531774374555_513fe1d2-f658-4af1-acfa-9a04da38b7a4-image.png

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

                                          M 1 Reply Last reply 20 Jul 2018, 10:36
                                          0

                                          • Login

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