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. Cannot change size and style of QCheckBox
QtWS25 Last Chance

Cannot change size and style of QCheckBox

Scheduled Pinned Locked Moved General and Desktop
10 Posts 5 Posters 19.7k Views
  • 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.
  • Z Offline
    Z Offline
    zing0000
    wrote on 22 Apr 2014, 03:29 last edited by
    #1

    I am using the QCheckBox widget and it functions fine - but it is very small, almost impossible to use physically when displayed on screen.

    I have tried various setStyleSheet commands, setMinimimSize, etc., and I must be getting the format wrong as nothing has the slightest effect.

    How do I simply make the checkbox larger?

    @
    QGroupBox* checkboxGroup = new QGroupBox();
    _eyeChk = new QCheckBox(tr("eyes:"));

    QGridLayout* checkboxLayout = new QGridLayout();
    checkboxLayout->addWidget(_eyeChk, 0, 0);
    

    ...
    checkboxGroup->setLayout(checkboxLayout);
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 22 Apr 2014, 07:24 last edited by
      #2

      bq. How do I simply make the checkbox larger?

      Your code snippet makes no attempt to change the size of the check box. The check box widget will be driven by the size of the group box you have placed it in. The size of the checkable part of the widget is styled using the indicator subcontrol:
      @
      QCheckBox checkbox("Eyes:");
      checkbox.setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
      checkbox.show();
      @
      http://qt-project.org/doc/qt-5/stylesheet-examples.html#customizing-qcheckbox

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zing0000
        wrote on 22 Apr 2014, 18:34 last edited by
        #3

        So here is a complete minimal App that shows that that does not work!

        "screenshot":https://drive.google.com/file/d/0B36C3VvTj33kdGNJNkVmY3JTQzA/edit?usp=sharing

        @
        #include "mainwindow.h"
        #include <QApplication>

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        MainWindow w;

        w.setGeometry(QRect(0,0,400,400));
        w.show();
        
        return a.exec&#40;&#41;;
        

        }
        @

        @
        #include "mainwindow.h"

        MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        {
        _eyeChk = new QCheckBox("Eyes:");
        _eyeChk->setStyleSheet("QCheckBox::indicator { width:100px; height: 100px;}");

        setCentralWidget(_eyeChk);
        

        }

        MainWindow::~MainWindow()
        {
        }
        @

        @
        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H

        #include <QMainWindow>
        #include <QGroupBox>
        #include <QCheckBox>
        #include <QGridLayout>
        #include <QDebug>

        #include <QListWidget>
        #include <QPushButton>
        #include <QLabel>
        #include <QDir>
        #include <QFileDialog>

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        public:
        MainWindow(QWidget *parent = 0);
        ~MainWindow();

        private:
        QCheckBox* _eyeChk;

        };

        #endif // MAINWINDOW_H
        @

        AFAICT I am following the styleshhet examples correctly (and the same as your code suggestion)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mranger90
          wrote on 22 Apr 2014, 19:03 last edited by
          #4

          What is your OS/Qt Version, etc?
          I have tried this on Ubuntu 14.04 with Qt 5.2.1 and it works as expected.
          On Win7 Qt5.2.0 /MSVC I can change the width/height independently, in other words the checkbox is always a square, but it will grow according to the smaller of the width/height style.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zing0000
            wrote on 22 Apr 2014, 21:46 last edited by
            #5

            I am using Qt5.1.0 with Win7.
            I also get the same behavior with Qt5.2.0 with Android.

            Are you saying that you ran my code and it worked for you?

            Thanks for your interest in this, I am trying to get an App released on Android and this is such an irritation!

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on 23 Apr 2014, 01:50 last edited by
              #6

              The ability to size the QCheckBox indicator is a function of the QStyle in use on the platform you are targeting.

              My example works just fine on Linux where I actually tested it (in a minimal Qt 5.2.1 application).

              My example does not resize the check box indicator on Windows 7 (QWindowsVistaStyle) with MSVC 2010 or MingW/GCC 4.8 and Qt 5.1.1 or 5.2.1 although it does leave space around the small indicator for the larger size. On Windows 7 with the "-style windows" option the checkbox is resized (but obviously the program looks wrong).

              Feel free to raise this as a bug.

              I cannot test on Android.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                junnellogbox.ph
                wrote on 23 Apr 2014, 02:43 last edited by
                #7

                try something like this

                @QApplication a(argc, argv);
                a.setStyleSheet("QCheckBox::indicator:unchecked {width: 181px;height: 91px; } QCheckBox::indicator:checked {width: 181px;height: 91px;) }");@

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  ChrisW67
                  wrote on 23 Apr 2014, 04:58 last edited by
                  #8

                  That makes no difference here.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JvdGlind
                    wrote on 23 Apr 2014, 09:42 last edited by
                    #9

                    If I understand it correctly, your problem lies in the fact the actual square is to small to properly click. By checking it out myself I learned that changing the height and width does nothing with the square. Try using an image of your own (I used the png on "wikipedia":https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/PNG_transparency_demonstration_2.png/280px-PNG_transparency_demonstration_2.png).

                    @MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    {
                    _eyeChk = new QCheckBox("Eyes:");
                    _eyeChk->setStyleSheet("QCheckBox::indicator { width:150px; height: 150px;} QCheckBox::indicator::checked {image: url(/home/jvdglind/Downloads/280px-PNG_transparency_demonstration_2.png);}");

                    setCentralWidget(_eyeChk);
                    

                    }@

                    Jeffrey VAN DE GLIND
                    Principle Consultant @ Nalys
                    www.nalys-group.com

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      zing0000
                      wrote on 23 Apr 2014, 17:32 last edited by
                      #10

                      Thanks! that is a good workaround!

                      1 Reply Last reply
                      0

                      7/10

                      23 Apr 2014, 02:43

                      • Login

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