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. (QSS) Why are two QPushButtons of different height if both are sized relative to their text height using "em" as unit
Forum Updated to NodeBB v4.3 + New Features

(QSS) Why are two QPushButtons of different height if both are sized relative to their text height using "em" as unit

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 385 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.
  • qwasder85Q Offline
    qwasder85Q Offline
    qwasder85
    wrote on last edited by qwasder85
    #1

    I have two QPushButtons, both H/V size policies are set to "Fixed", they sit next to one another in a QHBoxLayout and my QSS for QPushButton is this:

    QPushButton
    {
        background-color: #3c9eb8;
        border: none;
        font-family: "Segoe UI";
        font-size: 8pt;
        color: white;
        outline: none;
        padding-left: 1.0em;
        padding-right: 1.0em;
        min-height: 2em;
        min-width: 4em;
    }
    

    This is the result:
    alt text
    How can they be of different height if the height is based on the font size, which is the same for both?
    I'm using Qt5.9 on Windows 10.

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

      Hi,

      You should add which Qt version you are using and the OS as well.

      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
      0
      • qwasder85Q Offline
        qwasder85Q Offline
        qwasder85
        wrote on last edited by
        #3

        Thanks, I did. Qt5.9, Windows 10.

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

          Can you share how you create the buttons ?

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

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

            I'm not sure if this is affecting it, but 'Open' has a descending character, p, whereas 'New' does not. I would still expect the buttons to have the same height if you created them the same way.

            qwasder85Q 1 Reply Last reply
            2
            • M mchinand

              I'm not sure if this is affecting it, but 'Open' has a descending character, p, whereas 'New' does not. I would still expect the buttons to have the same height if you created them the same way.

              qwasder85Q Offline
              qwasder85Q Offline
              qwasder85
              wrote on last edited by
              #6

              @mchinand That's the only difference I could make out as well. But the definiton of "em" states that the unit's size only depends on the size of the letter 'm'.

              1 Reply Last reply
              0
              • SGaistS SGaist

                Can you share how you create the buttons ?

                qwasder85Q Offline
                qwasder85Q Offline
                qwasder85
                wrote on last edited by qwasder85
                #7

                @SGaist said in (QSS) Why are two QPushButtons of different height if both are sized relative to their text height using "em" as unit:

                Can you share how you create the buttons ?

                Sure:

                    m_p_new_button = new QPushButton;
                    m_p_new_button->setText(tr("New"));
                    m_p_new_button->setEnabled(true);
                    m_p_new_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
                
                    m_p_open_button = new QPushButton;
                    m_p_open_button->setText(tr("Open"));
                    m_p_open_button->setEnabled(false); // Enabled dynamically
                    m_p_open_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
                
                    QHBoxLayout* p_button_layout = new QHBoxLayout;
                    p_button_layout->setSpacing(5);
                    p_button_layout->addWidget(m_p_new_button);
                    p_button_layout->addWidget(m_p_open_button);
                
                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