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. Changed the color and the style of push button and it doesn't work anymore
Forum Updated to NodeBB v4.3 + New Features

Changed the color and the style of push button and it doesn't work anymore

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.9k 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.
  • P Offline
    P Offline
    Project try
    wrote on last edited by
    #1

    Hey guys

    I have a problem , I tried to change the push button's style and color of the font but now I can't press it , I was reading about it but let me just post the code here:

    @
    GPA_C=new QPushButton;

    GPA_C->setText("Compute MY GPA!");
    GPA_C->setStyleSheet("color:red;font:bold 13px; padding:5px; border-width:2px;border-style:outset;border-radius:12px; border-color:black");

    @

    now it says if you want to fix the click problem you should do this:
    @
    QPushButton#evilButton:pressed {
    background-color: rgb(224, 0, 0);
    border-style: inset;
    }

    @

    not sure what is he doing here , I created a class to compute the gpa but i can't do what he did here , is there a solution guys ?

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Try without #evilButton

      I guess you didn't use QObject::setObjectName() to give your button an ID

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Project try
        wrote on last edited by
        #3

        not sure if I can understand you , but could you please put some code ? , also what does even mean :
        @
        QPushButton object:pressed{//..
        }
        @

        and can I just fix this another way ?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Project try
          wrote on last edited by
          #4

          tried to do this:

          @

          GPA_C->setStyleSheet("color:red;font:bold 13px; padding:5px; border-width:1.5px;border-style:outset;border-radius:12px; border-color:black");

          //fix:
          GPA_C->setStyleSheet("background-color: rgb(224, 0, 0)");

          @

          it worked but the colors sucks now , also it's not the same as it was , like the font and stuff.

          edit: sorry forgot about the pressed thing , but how can I do that now to fix this problem ?

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            Normally you set stylesheets on your qApplication. As a result all your pushbuttons will look the same. Use it like below. Took the example from "the stylesheet docs":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#style-sheet-usage
            @
            qApp->setStyleSheet("
            QPushButton {
            background-color: red;
            border-style: outset;
            border-width: 2px;
            border-radius: 10px;
            border-color: beige;
            font: bold 14px;
            min-width: 10em;
            padding: 6px;
            }
            QPushButton:pressed {
            background-color: rgb(224, 0, 0);
            border-style: inset;
            }
            ")
            @

            Btw i added lines for readability. If you test line per line it's easier to see what causes a certain effect.

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Project try
              wrote on last edited by
              #6

              Thanks man , I learnt something ^^ , so it's better to make a custom look for anything in the main function instead of the dialog's class ?

              it worked by the way , thanks buddy ^^

              1 Reply Last reply
              0
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #7

                bq. so it’s better to make a custom look for anything in the main function instead of the dialog’s class ?

                Yes unless you want every dialog to look different.

                Happy i could help.

                Qt Certified Specialist
                www.edalsolutions.be

                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