Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSS : Make a QDoubleSpinBox looks like a QLabel when disabled



  • Hi,
    I am trying to make a QDoubleSpinBox looks like a QLabel when disabled. So far, I am pretty satisfied with it. However, I wasn't able to align the text on the right.
    From the documentation I know that text-align is not the solution since it is not supported for QDoubleSpinBox or QLineEdit (even if I tried).
    I have tried a lot of things :

    QDoubleSpinBox {
      qproperty-alignment: 'AlignVCenter | AligRight';
    }
    
    QDoubleSpinBox QLineEdit {
      qproperty-alignment: 'AlignVCenter | AligRight';
    }
    
    QDoubleSpinBox * {
      qproperty-alignment: 'AlignVCenter | AligRight';
    }
    

    And yet the content of the spin box stays align on the left side of the underlying line edit. I even tried to do the following :
    QLineEdit {
    qproperty-alignment: 'AlignVCenter | AligRight';
    }

    Could anyone help me with this?



  • Instead of faking it, you could actually work with a changing component by using a Loader like this:

    Loader {
            anchors.fill: parent
            sourceComponent:  {
                    switch(whatever) {
                            case 0: return firstComponent;
                            case 1: return secondComponent;
                            case 2: return thirdComponent;
                            default: return defaultComponent;
                    }
            }
    }
    Component {
            id: firstCompoment
            QDoubleSpinBox {
                    // (...)
            }
    Component {
            id: secondComponent
            QLabel {
                    // (...)
            }
    

Log in to reply