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 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
                      • R Offline
                        R Offline
                        rezaMSLM
                        wrote on last edited by
                        #24

                        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:

                        alt text

                        when showing one LED the other one is affected!

                        mrjjM 1 Reply Last reply
                        0
                        • R rezaMSLM

                          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:

                          alt text

                          when showing one LED the other one is affected!

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

                          @rezaMSLM
                          well i imagined you defined a big style sheet with
                          the names of all the LED
                          and set it once.
                          then hide() /show them

                          you can set stylesheet on mainwindow and it affects them also
                          no need to do directly on radiobutton.

                          R 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @rezaMSLM
                            well i imagined you defined a big style sheet with
                            the names of all the LED
                            and set it once.
                            then hide() /show them

                            you can set stylesheet on mainwindow and it affects them also
                            no need to do directly on radiobutton.

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

                            @mrjj
                            I dont understand
                            please explain more

                            mrjjM 1 Reply Last reply
                            0
                            • R rezaMSLM

                              @mrjj
                              I dont understand
                              please explain more

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

                              @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::xxx

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

                              R 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @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::xxx

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

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

                                @mrjj
                                thanks alot

                                there will be 3 or 4 groups and about 10 to 15 LED's in each group

                                mrjjM 1 Reply Last reply
                                0
                                • R rezaMSLM

                                  @mrjj
                                  thanks alot

                                  there will be 3 or 4 groups and about 10 to 15 LED's in each group

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

                                  @rezaMSLM
                                  Ok, im a bit concerned about using names directly
                                  ui->radioButton_2->show();
                                  wont that become tons of names ?

                                  R 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @rezaMSLM
                                    Ok, im a bit concerned about using names directly
                                    ui->radioButton_2->show();
                                    wont that become tons of names ?

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

                                    @mrjj
                                    yes it will
                                    but i think this is the only way i can do

                                    i'd like to use this LED indicator but dont know how put LED's in the coordinates i want to

                                    LED example

                                    mrjjM 1 Reply Last reply
                                    0
                                    • R rezaMSLM

                                      @mrjj
                                      yes it will
                                      but i think this is the only way i can do

                                      i'd like to use this LED indicator but dont know how put LED's in the coordinates i want to

                                      LED example

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

                                      @rezaMSLM
                                      well its possible to do more generic.
                                      sender()) or lambda

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

                                      R 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @rezaMSLM
                                        well its possible to do more generic.
                                        sender()) or lambda

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

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

                                        @mrjj
                                        yes LED's are Fixed

                                        mrjjM 1 Reply Last reply
                                        0
                                        • R rezaMSLM

                                          @mrjj
                                          yes LED's are Fixed

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

                                          @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=0

                                          i use promotion. that allows you to copy them around and at run time they be the leds.

                                          did u try sample?

                                          R 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