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 change QCheckBox label size?

How to change QCheckBox label size?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.5k 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.
  • Q Offline
    Q Offline
    qwe3
    wrote on last edited by
    #1

    Hi,

    I would like to have QCheckBox, which has fixed width, so I did:

    setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);
    setFixedWidth(170);
    setStyleSheet("QCheckBox {background:red}"); // only to show real shape of checkBox
    

    I get:
    checkBox.png

    Now, when I clicked in the red area, checkBox doesn't change state ( checked / unchecked ). So I think I have to change the size of the pink area ( so the label, where is "TEXT" ).

    Pl45m4P 1 Reply Last reply
    0
    • Q qwe3

      Hi,

      I would like to have QCheckBox, which has fixed width, so I did:

      setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);
      setFixedWidth(170);
      setStyleSheet("QCheckBox {background:red}"); // only to show real shape of checkBox
      

      I get:
      checkBox.png

      Now, when I clicked in the red area, checkBox doesn't change state ( checked / unchecked ). So I think I have to change the size of the pink area ( so the label, where is "TEXT" ).

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @qwe3 said in How to change QCheckBox label size?:

      Now, when I clicked in the red area, checkBox doesn't change state ( checked / unchecked )

      Because the actual clickable area is the box + the text area. The red background area is just a kind of frame around it.

      If you look into the source, you can see that there is a check, before the state is going to change. It checks whether the mouse hits the CheckBoxClickRect which is a subStyle element (your pink area).

      • https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qabstractbutton.cpp.html#_ZN15QAbstractButton15mousePressEventEP11QMouseEvent
      • https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qcheckbox.cpp.html#_ZNK9QCheckBox9hitButtonERK6QPoint

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved