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

    @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
                        • mrjjM mrjj

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

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

                          did u try sample?

                          yes
                          but dont know how to put LED's on the places i want on map

                          mrjjM 1 Reply Last reply
                          0
                          • R rezaMSLM

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

                            did u try sample?

                            yes
                            but dont know how to put LED's on the places i want on map

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

                            @rezaMSLM
                            you just copy the widget and place it where u want ?
                            alt text
                            the widget is the led. so it work the same as radio buttons.

                            R 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @rezaMSLM
                              you just copy the widget and place it where u want ?
                              alt text
                              the widget is the led. so it work the same as radio buttons.

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

                              @mrjj
                              I still don't understand how to put LED's on different places on the map

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

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

                              please explain more.
                              how to use promotion?

                              mrjjM 1 Reply Last reply
                              0
                              • R rezaMSLM

                                @mrjj
                                I still don't understand how to put LED's on different places on the map

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

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

                                please explain more.
                                how to use promotion?

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

                                @rezaMSLM
                                you put a widget on the form and right click it
                                select Promote
                                then give it the class name and include
                                alt text
                                Then click Add
                                and then promote.
                                When run, its now a Led.
                                you must have ledIndicator.cpp and .h added to project

                                also explained here
                                http://doc.qt.io/qt-5/designer-using-custom-widgets.html

                                1 Reply Last reply
                                1

                                • Login

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