Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-124150

QAbstractSpinBox size hint miscalculated for Windows 11 style

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 6.7.2, 6.8.0 FF
    • 6.7.0
    • Widgets: Styles
    • None
    • Windows 11
    • Windows
    • b457376c0 (dev), 495e5cbbb (6.7)

      The width (size hint) of QSpinBox is too small, if the application style is set to Windows 11. If the style is changed to Windows the calculation is done correct.

      The problem is also true for other widgets derived from QAbstractSpinBox (e.g. QDateTimeEdit).

      #include <QApplication>
      #include <QtWidgets>
      
      class MainWindow : public QMainWindow
      {
      public:
          MainWindow(QWidget *parent = nullptr) : QMainWindow{parent} {
              sb.setMaximum(99999);
              sb.setValue(12345);
              
              sbNoButton.setMaximum(99999);
              sbNoButton.setValue(12345);
              sbNoButton.setButtonSymbols(QAbstractSpinBox::NoButtons);
              
              hLayout.addWidget(&sb);
              hLayout.addWidget(&sbNoButton);
              hLayout.addStretch(1);
              
              vLayout.addLayout(&hLayout);
              vLayout.addWidget(&debug);
              
              central.setLayout(&vLayout);
              setCentralWidget(&central);
          };
      protected:
          void resizeEvent(QResizeEvent *event) override {
              debug.clear();
              QString s;
              QDebug out{&s};
              out << " sb size: \t" << sb.size()
                  << "\t sbNoButton size: \t" << sbNoButton.size() << "\n";
              out << "sb hint: \t" << sb.sizeHint()
                  << "\t sbNoButton hint: \t" << sbNoButton.sizeHint() << "\n";
              out << "sb min. hint: \t" << sb.minimumSizeHint()
                  << "\t sbNoButton min. hint: \t" << sbNoButton.minimumSizeHint() << "\n";
              out << "sb min.: \t" << sb.minimumSize()
                  << "\t sbNoButton min.: \t" << sbNoButton.minimumSize() << "\n";
      
              debug.append(s);
              QMainWindow::resizeEvent(event);
          };
      private:
          QSpinBox sb;
          QSpinBox sbNoButton;
          QHBoxLayout hLayout;
          QVBoxLayout vLayout;
          QTextEdit debug;
          QWidget central;
      };
      
      int main(int argc, char *argv[])
      {
          //QApplication::setStyle(QStyleFactory::create("Windows"));
          QApplication::setStyle(QStyleFactory::create("windows11"));
          QApplication a(argc, argv);
      
          MainWindow w;
          //w.setWindowTitle("Windows Style");
          w.setWindowTitle("Windows 11 Style");
          w.show();    return a.exec();
      } 

        For Gerrit Dashboard: QTBUG-124150
        # Subject Branch Project Status CR V

            wladimir.leuschner Wladimir Leuschner
            stephan_cb Stephan Schmitt
            Votes:
            4 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes