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 can I print my QPushButton?
Qt 6.11 is out! See what's new in the release blog

How can I print my QPushButton?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 6 Posters 2.8k Views 1 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.
  • Taz742T Taz742

    @victor-wang
    something like this:
    QPushButton{ background-color: blue; }
    QPushButton:disabled{ background-color: yellow; }
    QPushButton:pressed{ background-color: orange; }
    QPushButton:focus:pressed{ background-color: black; }
    QPushButton:focus{ background-color: green; }
    QPushButton:hover{ background-color: red; }
    QPushButton:checked{ background-color: pink; }

    V Offline
    V Offline
    victor wang
    wrote on last edited by victor wang
    #3

    @Taz742
    You mean add those functions in?
    Could you describe more detailed?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #4

      Hope you got a chance to look at documentation

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      V 1 Reply Last reply
      4
      • dheerendraD dheerendra

        Hope you got a chance to look at documentation

        V Offline
        V Offline
        victor wang
        wrote on last edited by
        #5

        @dheerendra
        I have no background-color on my computer.
        Why is happening ?

        jsulmJ 1 Reply Last reply
        0
        • V victor wang

          @dheerendra
          I have no background-color on my computer.
          Why is happening ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @victor-wang Not related to your question: why do you open /dev/sda1? Do you assume /dev/sda1 is USB device? It is most probably not. You should not use such hard coded devices in your code as they can vary even on same machine depending on which/how many devices are connected.

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

          V 1 Reply Last reply
          0
          • jsulmJ jsulm

            @victor-wang Not related to your question: why do you open /dev/sda1? Do you assume /dev/sda1 is USB device? It is most probably not. You should not use such hard coded devices in your code as they can vary even on same machine depending on which/how many devices are connected.

            V Offline
            V Offline
            victor wang
            wrote on last edited by
            #7

            @jsulm
            That because I don't know how to judge the place that if USB is in and will mount to where.

            jsulmJ 1 Reply Last reply
            0
            • V victor wang

              @jsulm
              That because I don't know how to judge the place that if USB is in and will mount to where.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @victor-wang It will not work this way. Qt does not provide functionality to detect a USB device. But you can use for example: http://libusb.org/

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

              V 1 Reply Last reply
              0
              • jsulmJ jsulm

                @victor-wang It will not work this way. Qt does not provide functionality to detect a USB device. But you can use for example: http://libusb.org/

                V Offline
                V Offline
                victor wang
                wrote on last edited by victor wang
                #9

                @jsulm
                Thank you!
                I will look at it later, first of all i have to solve current problem.
                Do you know how to fix it?

                This is my current code now.

                I write it like this.

                QPalette pal = ui->pushButtonPT_USB_ResultLight1->palette();
                pal.setColor(QPalette::Button,Qt::green);
                ui->pushButtonPT_USB_ResultLight1->setPallette(pal);
                
                J.HilkJ 1 Reply Last reply
                0
                • V victor wang

                  @jsulm
                  Thank you!
                  I will look at it later, first of all i have to solve current problem.
                  Do you know how to fix it?

                  This is my current code now.

                  I write it like this.

                  QPalette pal = ui->pushButtonPT_USB_ResultLight1->palette();
                  pal.setColor(QPalette::Button,Qt::green);
                  ui->pushButtonPT_USB_ResultLight1->setPallette(pal);
                  
                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #10

                  @victor-wang
                  like @dheerendra said, use StyleSheets:

                  //Instead of setPalette and repaint use:
                  ui->pushButtonPT_USB_ResultLight1->setStyleSheet("QPushButton{background-color:red;}");
                  
                  //and for the else
                  ui->pushButtonPT_USB_ResultLight1->setStyleSheet("QPushButton{background-color:green;}");
                  

                  PS:
                  you need better names for your variables..


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  V 1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @victor-wang
                    like @dheerendra said, use StyleSheets:

                    //Instead of setPalette and repaint use:
                    ui->pushButtonPT_USB_ResultLight1->setStyleSheet("QPushButton{background-color:red;}");
                    
                    //and for the else
                    ui->pushButtonPT_USB_ResultLight1->setStyleSheet("QPushButton{background-color:green;}");
                    

                    PS:
                    you need better names for your variables..

                    V Offline
                    V Offline
                    victor wang
                    wrote on last edited by
                    #11

                    @J.Hilk

                    Thank you!!!!!!!
                    It worked perfect!
                    thank you so much

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      Hi,

                      Since you are using Qt, KDE's Solid framework might make thing simpler to detect USB mass storage devices.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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