Question

I am new to QT. I have several QDialogs in my QT project. I have created a generic class to change the properties of widgets inside QDialogs. My generic class has a static method which will change the properties of widgets.

void MyClass::setFontsizeToWidgets(float modValue, QObject obj)
{
    QFont f;
    float pointSize = 0.0;

    QList<QPushButton*> buttons = obj.findChildren<QPushButton*>();

    foreach ( QPushButton * button, buttons)
    {
        f = button->font();
        pointSize = f.pointSizeF();
        f.setPointSizeF(pointSize*modValue);
        button->setFont(f);
    }
}

Now my questions is, how to pass the QDialog as a object to the above static method from QDialog class? So that the static method will change the font size of the QPushButton(s) in the QDialog.

Était-ce utile?

La solution

You can do it like this:

void MyClass::setFontsizeToWidgets(float modValue, QObject *obj)
{
    //do something 
}

void MyDialog::someFunction() //this is a function of your QDialog class
{
    MyClass::setFontsizeToWidgets(10, this);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top