How to update entire window on change in QProxyStyle?
-
Hi
It might be due being in a layout ?
Did you try calling updateGeometry() on the buttons ? -
@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
-
@mrjj I found a way around, by recreating a new
ProxyStyle
object each time the value ofminBtnBorder
is changed and then applying this to theqApp
.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.
-
@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(); -
@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).
-
@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.