0
votes

There is a situation: for example I have a button in the complex dialog. I need to disable this button until other widgets (QLineEdit) are empty.

I think the best way to monitor widget's state is to use QTimer and special function to change button state:

void foo()
{
    if( !lineEdit1->text().isEmpty() && !lineEdit2->text().isEmpty() )
        btn->setEnabled( true )
    else
        btn->setEnabled( false );
} 

Are there other ways to solve this problem? May be using QAction is better, or it will be an overhead?

PS: I can't to use signals and slots, because observing widgets (panels with widgets) are created in the separate modules, and they don't know about dialog's slots.

1

1 Answers

3
votes

The best way is using the signal/slot mechanizm to trigger changes in the QLineEdit. For example:

Connect line edit's textChanged signal to the appropriate slot

connect(lineEdit1, SIGNAL(textChanged(const QString &)), this, SLOT(onTextChanged(const QString &));

Slot implementation.

void onTextChanged(const QString &text)
{
    if( !text.isEmpty() )
        btn->setEnabled( true )
    else
        btn->setEnabled( false );
}