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 set size and font for a QPushbutton
Forum Updated to NodeBB v4.3 + New Features

How to set size and font for a QPushbutton

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 2 Posters 55.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.
  • M Offline
    M Offline
    mostefa
    wrote on last edited by
    #2

    Hi,

    @tomy you can customize your QPushButton style with qt stylesheet, take a look at:

    http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qpushbutton

    tomyT 1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #3

      For your need :

      QPushButton#my_button
      {
      font: bold;/or italic/
      background-color: red;
      font-size: 36px;/for example/
      height: 48px;/for example/
      width: 120px;/for example/
      }

      You can change the position of the button with the layout of the parent widget

      1 Reply Last reply
      2
      • M mostefa

        Hi,

        @tomy you can customize your QPushButton style with qt stylesheet, take a look at:

        http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qpushbutton

        tomyT Offline
        tomyT Offline
        tomy
        wrote on last edited by
        #4

        @mostefa

        you can customize your QPushButton style with qt stylesheet, take a look at:
        http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qpushbutton

        Thank you. I looked at this link but couldn't find useful method for the tasks I mentioned.

        Would you please, given the button my_button do the changes?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mostefa
          wrote on last edited by mostefa
          #5

          my_button->setStyleSheet("font: bold;background-color: red;font-size: 36px;height: 48px;width: 120px;}

          1 Reply Last reply
          1
          • tomyT Offline
            tomyT Offline
            tomy
            wrote on last edited by tomy
            #6

            Three errors:

            1-missing terminating " character
            my_button ->setStylesheet("font: bold;background-color: red;font-size: 36px;height: 48px;width: 120px;}

            2- 'class QPushButton' has no member named 'setStylesheet'
            my_button ->setStylesheet("font: bold;background-color: red;font-size: 36px;height: 48px;width: 120px;}

            3- expected ')' before ';' token
            connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(get(QString)));

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mostefa
              wrote on last edited by mostefa
              #7

              @tomy

              Sorry , the function is setStyleSheet and not setStylesheet

              try with this line:

              my_button->setStyleSheet("font: bold;background-color: red;font-size: 36px;height: 48px;width: 120px;");

              1 Reply Last reply
              3
              • tomyT Offline
                tomyT Offline
                tomy
                wrote on last edited by
                #8

                Thank you. It worked now. Using it we have:
                font
                background-color
                font-size
                height & width

                These are good and applicable. But what for:
                Positioning and the color of font?
                Do we have such facilities?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mostefa
                  wrote on last edited by
                  #9

                  @tomy

                  Glad to see that this helped you,

                  for font color , the property is color, you can write : color: white;//for example,

                  I advise you to list of available properties that you can use with stylesheet from Qt doc:

                  http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties

                  and to see stylesheet example from qt examples:

                  http://doc.qt.io/qt-5/qtwidgets-widgets-stylesheet-example.html

                  tomyT 1 Reply Last reply
                  2
                  • M mostefa

                    @tomy

                    Glad to see that this helped you,

                    for font color , the property is color, you can write : color: white;//for example,

                    I advise you to list of available properties that you can use with stylesheet from Qt doc:

                    http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties

                    and to see stylesheet example from qt examples:

                    http://doc.qt.io/qt-5/qtwidgets-widgets-stylesheet-example.html

                    tomyT Offline
                    tomyT Offline
                    tomy
                    wrote on last edited by
                    #10

                    @mostefa

                    I advise you to list of available properties that you can use with stylesheet from Qt doc:

                    http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties

                    Thank you. Color was used but about positioning a button not yet!
                    I fount this using your link.
                    It appears to be what I need. But how to use it? I tried some ways using the contents of the page but no result.

                    and to see stylesheet example from qt examples:

                    http://doc.qt.io/qt-5/qtwidgets-widgets-stylesheet-example.html

                    I also looked at it. It's about Designer, which widgets can be customized in property window (coding seems useless)

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mostefa
                      wrote on last edited by
                      #11

                      @tomy

                      Usually for positioning : buttons,widgets ,i am using Layout , i never used position property of stylesheet not with stylesheet,i do you have a layout on your application? are you using Qt designer ?

                      If you are using Qt Designer positions of buttons can be changed directly with drag and drop

                      And yes widgets can be customized from qt Designer , on your mainWindow , on stylesheet property.

                      tomyT 1 Reply Last reply
                      0
                      • M mostefa

                        @tomy

                        Usually for positioning : buttons,widgets ,i am using Layout , i never used position property of stylesheet not with stylesheet,i do you have a layout on your application? are you using Qt designer ?

                        If you are using Qt Designer positions of buttons can be changed directly with drag and drop

                        And yes widgets can be customized from qt Designer , on your mainWindow , on stylesheet property.

                        tomyT Offline
                        tomyT Offline
                        tomy
                        wrote on last edited by
                        #12

                        @mostefa
                        The problem is that I don't use Designer, just pure code.
                        I have a gridlayout, QVBoxlayout and QHBoxlayout for laying out the widgets.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mostefa
                          wrote on last edited by
                          #13

                          @tomy

                          You can position your widget width QGridLayout, without any problem

                          http://doc.qt.io/qt-5/qgridlayout.html#addWidget

                          When you add widgets with gridLayout you choose the row , the column , the row span and column span, and the alignement

                          row and column are represented on the following picture:

                          alt text

                          1 Reply Last reply
                          2
                          • tomyT Offline
                            tomyT Offline
                            tomy
                            wrote on last edited by
                            #14

                            Thank you for the time you considered to help me. I'm appreciative .

                            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