Results 1 to 2 of 2

Thread: How to set a fixed size to QPushButton on stylesheet? Adding padding is resizing it

  1. #1
    Join Date
    Apr 2019
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to set a fixed size to QPushButton on stylesheet? Adding padding is resizing it

    Hi,
    I'm trying to set a fixed size to a QPushButton by setting it on stylesheet, but when adding a padding-left to the button, it's being resized to fixed-width + padding-left. I want it to keep the fixed size that i set to the button. And i want to avoid calling SetFixedWidth and SetFixedSize methods because i want it to be loaded of a external stylesheet file. I Already try to set sizePolicy to fixed but ii keeps the same behavior.

    Here are my definitions:

    button->setStyleSheet("QPushButton {"
    " text-align:left;"
    " margin: 0px;"
    " padding-left: 32px;"
    " border: none;"
    " min-height: 48px;"
    " max-height: 48px;"
    " min-width: 248px;"
    " max-width: 248px;"
    " background-color: #4000FF99;"
    "}");

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set a fixed size to QPushButton on stylesheet? Adding padding is resizing

    The min-width, max-width, min-height, and max-height pertain to the content area of the box model (see https://doc.qt.io/qt-5/stylesheet-re...ax-width-propl and https://doc.qt.io/qt-5/stylesheet-cu...html#box-model)
    Left padding puts empty space outside the content box making the overall size larger. Padding, border width and margins all default to zero.

    If you want the total size at the outside of the margin to be fixed then you need some basic arithmetic to ensure the four components add to a fixed value.

Similar Threads

  1. Replies: 0
    Last Post: 14th February 2012, 16:43
  2. Adding some padding to a button
    By scarleton in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2010, 16:18
  3. Replies: 4
    Last Post: 20th November 2009, 13:25
  4. QPushButton stylesheet problem
    By blukske in forum Qt Programming
    Replies: 10
    Last Post: 24th August 2009, 22:51
  5. A fixed size window?
    By adorp in forum Qt Tools
    Replies: 4
    Last Post: 25th July 2007, 19:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.