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 update entire window on change in QProxyStyle?
Forum Updated to NodeBB v4.3 + New Features

How to update entire window on change in QProxyStyle?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qproxystyleqpushbuttonqwidgetpainting issues
16 Posts 3 Posters 1.9k Views 3 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.
  • mrjjM mrjj

    @CJha

    hi
    I cannot make it scale/update at all.

    What type of layout did you use ?

    CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by CJha
    #7

    @mrjj Hi, that is strange. I used a normal layout in Qt Designer. Here is an image:

    LayoutReq.PNG

    I didn't change anything about the layout, I just put it there and that is all.

    mrjjM 1 Reply Last reply
    0
    • CJhaC CJha

      @mrjj Hi, that is strange. I used a normal layout in Qt Designer. Here is an image:

      LayoutReq.PNG

      I didn't change anything about the layout, I just put it there and that is all.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #8

      @CJha
      and buttons have default sizePolizy ?

      Could you post the UI file content ?

      mrjjM CJhaC 2 Replies Last reply
      0
      • mrjjM mrjj

        @CJha
        and buttons have default sizePolizy ?

        Could you post the UI file content ?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #9

        @mrjj

        Ok, got it now.

        CJhaC 1 Reply Last reply
        1
        • mrjjM mrjj

          @CJha
          and buttons have default sizePolizy ?

          Could you post the UI file content ?

          CJhaC Offline
          CJhaC Offline
          CJha
          wrote on last edited by
          #10

          @mrjj Yes, the sizePolicy, min and max size, etc is all default. All I did was change the text on the buttons.

          Here is the UI file content:

          /********************************************************************************
          ** Form generated from reading UI file 'mainwindowggYFGS.ui'
          **
          ** Created by: Qt User Interface Compiler version 5.15.2
          **
          ** WARNING! All changes made in this file will be lost when recompiling UI file!
          ********************************************************************************/
          
          #ifndef MAINWINDOWGGYFGS_H
          #define MAINWINDOWGGYFGS_H
          
          #include <QtCore/QVariant>
          #include <QtWidgets/QApplication>
          #include <QtWidgets/QHBoxLayout>
          #include <QtWidgets/QLabel>
          #include <QtWidgets/QMainWindow>
          #include <QtWidgets/QPushButton>
          #include <QtWidgets/QSpacerItem>
          #include <QtWidgets/QSpinBox>
          #include <QtWidgets/QVBoxLayout>
          #include <QtWidgets/QWidget>
          
          QT_BEGIN_NAMESPACE
          
          class Ui_MainWindowClass
          {
          public:
              QWidget *centralWidget;
              QVBoxLayout *verticalLayout;
              QHBoxLayout *horizontalLayout;
              QLabel *label;
              QSpinBox *btnBorder_spin;
              QSpacerItem *horizontalSpacer;
              QHBoxLayout *horizontalLayout_2;
              QPushButton *btn_1;
              QSpacerItem *horizontalSpacer_2;
              QPushButton *btn_2;
              QSpacerItem *horizontalSpacer_3;
              QPushButton *btn_3;
          
              void setupUi(QMainWindow *MainWindowClass)
              {
                  if (MainWindowClass->objectName().isEmpty())
                      MainWindowClass->setObjectName(QString::fromUtf8("MainWindowClass"));
                  MainWindowClass->resize(311, 73);
                  centralWidget = new QWidget(MainWindowClass);
                  centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
                  verticalLayout = new QVBoxLayout(centralWidget);
                  verticalLayout->setSpacing(6);
                  verticalLayout->setContentsMargins(11, 11, 11, 11);
                  verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
                  horizontalLayout = new QHBoxLayout();
                  horizontalLayout->setSpacing(6);
                  horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
                  label = new QLabel(centralWidget);
                  label->setObjectName(QString::fromUtf8("label"));
          
                  horizontalLayout->addWidget(label);
          
                  btnBorder_spin = new QSpinBox(centralWidget);
                  btnBorder_spin->setObjectName(QString::fromUtf8("btnBorder_spin"));
                  btnBorder_spin->setMaximum(999);
                  btnBorder_spin->setValue(10);
          
                  horizontalLayout->addWidget(btnBorder_spin);
          
                  horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
          
                  horizontalLayout->addItem(horizontalSpacer);
          
          
                  verticalLayout->addLayout(horizontalLayout);
          
                  horizontalLayout_2 = new QHBoxLayout();
                  horizontalLayout_2->setSpacing(6);
                  horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
                  btn_1 = new QPushButton(centralWidget);
                  btn_1->setObjectName(QString::fromUtf8("btn_1"));
          
                  horizontalLayout_2->addWidget(btn_1);
          
                  horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
          
                  horizontalLayout_2->addItem(horizontalSpacer_2);
          
                  btn_2 = new QPushButton(centralWidget);
                  btn_2->setObjectName(QString::fromUtf8("btn_2"));
          
                  horizontalLayout_2->addWidget(btn_2);
          
                  horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
          
                  horizontalLayout_2->addItem(horizontalSpacer_3);
          
                  btn_3 = new QPushButton(centralWidget);
                  btn_3->setObjectName(QString::fromUtf8("btn_3"));
          
                  horizontalLayout_2->addWidget(btn_3);
          
          
                  verticalLayout->addLayout(horizontalLayout_2);
          
                  MainWindowClass->setCentralWidget(centralWidget);
          
                  retranslateUi(MainWindowClass);
          
                  QMetaObject::connectSlotsByName(MainWindowClass);
              } // setupUi
          
              void retranslateUi(QMainWindow *MainWindowClass)
              {
                  MainWindowClass->setWindowTitle(QCoreApplication::translate("MainWindowClass", "MainWindow", nullptr));
                  label->setText(QCoreApplication::translate("MainWindowClass", "Button Side Borders:", nullptr));
                  btnBorder_spin->setSuffix(QCoreApplication::translate("MainWindowClass", " px", nullptr));
                  btn_1->setText(QCoreApplication::translate("MainWindowClass", "Button 1: 0", nullptr));
                  btn_2->setText(QCoreApplication::translate("MainWindowClass", "Button 2: 0", nullptr));
                  btn_3->setText(QCoreApplication::translate("MainWindowClass", "Button 3: Demo", nullptr));
              } // retranslateUi
          
          };
          
          namespace Ui {
              class MainWindowClass: public Ui_MainWindowClass {};
          } // namespace Ui
          
          QT_END_NAMESPACE
          
          #endif // MAINWINDOWGGYFGS_H
          
          1 Reply Last reply
          1
          • mrjjM mrjj

            @mrjj

            Ok, got it now.

            CJhaC Offline
            CJhaC Offline
            CJha
            wrote on last edited by
            #11

            @mrjj I found a way around, by recreating a new ProxyStyle object each time the value of minBtnBorder is changed and then applying this to the qApp.

            void MainWindow::on_btnBorder_spin_valueChanged(int val)
            {
               minBtnBorder = val;
               auto proxyStyle = new ProxyStyle;
               proxyStyle->setBaseStyle(QStyleFactory::create("Fusion"));
               qApp->setStyle(proxyStyle);
               hide();
               show();
            }
            

            It is a workaround at best though.

            mrjjM 1 Reply Last reply
            1
            • CJhaC CJha

              @mrjj I found a way around, by recreating a new ProxyStyle object each time the value of minBtnBorder is changed and then applying this to the qApp.

              void MainWindow::on_btnBorder_spin_valueChanged(int val)
              {
                 minBtnBorder = val;
                 auto proxyStyle = new ProxyStyle;
                 proxyStyle->setBaseStyle(QStyleFactory::create("Fusion"));
                 qApp->setStyle(proxyStyle);
                 hide();
                 show();
              }
              

              It is a workaround at best though.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #12

              @CJha
              Good. at least we have a "fix"

              The odd thing is that setText

              void QAbstractButton::setText(const QString &text)
              {
                  Q_D(QAbstractButton);
                  if (d->text == text)
                      return;
                  d->text = text;
              #ifndef QT_NO_SHORTCUT
                  QKeySequence newMnemonic = QKeySequence::mnemonic(text);
                  setShortcut(newMnemonic);
              #endif
                  d->sizeHint = QSize();
                  update();
                  updateGeometry();
              #ifndef QT_NO_ACCESSIBILITY
                  QAccessibleEvent event(this, QAccessible::NameChanged);
                  QAccessible::updateAccessibility(&event);
              #endif
              }
              

              just calls
              update();
              updateGeometry();

              CJhaC Christian EhrlicherC 2 Replies Last reply
              1
              • mrjjM mrjj

                @CJha
                Good. at least we have a "fix"

                The odd thing is that setText

                void QAbstractButton::setText(const QString &text)
                {
                    Q_D(QAbstractButton);
                    if (d->text == text)
                        return;
                    d->text = text;
                #ifndef QT_NO_SHORTCUT
                    QKeySequence newMnemonic = QKeySequence::mnemonic(text);
                    setShortcut(newMnemonic);
                #endif
                    d->sizeHint = QSize();
                    update();
                    updateGeometry();
                #ifndef QT_NO_ACCESSIBILITY
                    QAccessibleEvent event(this, QAccessible::NameChanged);
                    QAccessible::updateAccessibility(&event);
                #endif
                }
                

                just calls
                update();
                updateGeometry();

                CJhaC Offline
                CJhaC Offline
                CJha
                wrote on last edited by
                #13

                @mrjj Yeah, that is very odd. Maybe something else is going on in the background that we are unable to get to!? Although, the code for setText() seems complete.

                mrjjM 1 Reply Last reply
                0
                • CJhaC CJha

                  @mrjj Yeah, that is very odd. Maybe something else is going on in the background that we are unable to get to!? Although, the code for setText() seems complete.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  @CJha

                  well i think it might be related to sizeHint() but I have no proof yet :)

                  1 Reply Last reply
                  1
                  • mrjjM mrjj

                    @CJha
                    Good. at least we have a "fix"

                    The odd thing is that setText

                    void QAbstractButton::setText(const QString &text)
                    {
                        Q_D(QAbstractButton);
                        if (d->text == text)
                            return;
                        d->text = text;
                    #ifndef QT_NO_SHORTCUT
                        QKeySequence newMnemonic = QKeySequence::mnemonic(text);
                        setShortcut(newMnemonic);
                    #endif
                        d->sizeHint = QSize();
                        update();
                        updateGeometry();
                    #ifndef QT_NO_ACCESSIBILITY
                        QAccessibleEvent event(this, QAccessible::NameChanged);
                        QAccessible::updateAccessibility(&event);
                    #endif
                    }
                    

                    just calls
                    update();
                    updateGeometry();

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    @mrjj said in How to update entire window on change in QProxyStyle?:

                    d->sizeHint = QSize();

                    I think this may be the reason. I would guess sizeFromContents() is only called when sizeHint is invalid. Simply set a breakpoint at ProxyStyle ::sizeFromContents() and take a look from where it is called (and why).

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    mrjjM 1 Reply Last reply
                    3
                    • Christian EhrlicherC Christian Ehrlicher

                      @mrjj said in How to update entire window on change in QProxyStyle?:

                      d->sizeHint = QSize();

                      I think this may be the reason. I would guess sizeFromContents() is only called when sizeHint is invalid. Simply set a breakpoint at ProxyStyle ::sizeFromContents() and take a look from where it is called (and why).

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #16

                      @Christian-Ehrlicher
                      Hi
                      Seems to call it from QPushButton::sizeHint() but I failed
                      to find way to trigger it without altering text.
                      I guess for full disclosure the source is needed and single step :9
                      I use wobog for it.

                      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