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 18.2k 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 rezaMSLM

    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?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on 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 last edited by
      #5

      0_1531799274463_Capture.JPG

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

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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
        0
        • mrjjM mrjj

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

          mrjjM 1 Reply Last reply
          0
          • R rezaMSLM

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

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #8

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

            R 1 Reply Last reply
            0
            • mrjjM mrjj

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

              R Offline
              R Offline
              rezaMSLM
              wrote on 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
              0
              • R rezaMSLM

                @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 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
                2
                • Pablo J. RoginaP Pablo J. Rogina

                  @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 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 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
                    1
                    • M MrShawn

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

                      mrjjM 1 Reply Last reply
                      0
                      • R rezaMSLM

                        @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

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

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

                        R 1 Reply Last reply
                        1
                        • mrjjM mrjj

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

                          R Offline
                          R Offline
                          rezaMSLM
                          wrote on 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
                          0
                          • R rezaMSLM

                            @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 Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 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
                            1
                            • jsulmJ jsulm

                              @rezaMSLM If you use layouts then it should resize automatically

                              R Offline
                              R Offline
                              rezaMSLM
                              wrote on 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 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 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

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

                                    mrjjM 1 Reply Last reply
                                    0
                                    • R rezaMSLM

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

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #21

                                      @rezaMSLM
                                      the background-color controls that.
                                      you can do
                                      background-color: rgb(47, 255, 11);
                                      to set a color using RGB

                                      R 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @rezaMSLM
                                        the background-color controls that.
                                        you can do
                                        background-color: rgb(47, 255, 11);
                                        to set a color using RGB

                                        R Offline
                                        R Offline
                                        rezaMSLM
                                        wrote on last edited by
                                        #22

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

                                        that controls all buttons color
                                        i want some red, some green and so on

                                        mrjjM 1 Reply Last reply
                                        0
                                        • R rezaMSLM

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

                                          that controls all buttons color
                                          i want some red, some green and so on

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #23

                                          @rezaMSLM
                                          You can use names.
                                          this is a MUST read.
                                          https://doc.qt.io/Qt-5/stylesheet-syntax.html

                                          QRadioButton#Name::indicator xxxxx

                                          but i think the other leds you found will work better for this that style sheet. but
                                          it should be doable.

                                          1 Reply Last reply
                                          0

                                          • Login

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