Important: Please read the Qt Code of Conduct -

Can this be done in Qt?

  • In one of my wxWidgets projects, I use the following code:

    void Fishermen::onUpdateAddMCButton( wxUpdateUIEvent &event )
        event.Enable( false); // disables the Ok button
        if (!TextCtrl_Add_Question->GetValue().empty() )
            if (!TextCtrl_Answer1->GetValue().empty() )
                if (!TextCtrl_Answer2->GetValue().empty() )
                    if (!TextCtrl_Answer3->GetValue().empty() )
                        if (!TextCtrl_Answer4->GetValue().empty() )
                            int selection = Choice_The_Answer_MC->GetSelection();
                            if (selection != wxNOT_FOUND) // equals -1 (no selection)
                                event.Enable( true);

    It makes sure there's text in the four TextCtrls and that something got selected in the comboBox. Once those conditions are satisfied, the OK button gets enabled.

    Does Qt have a similar ability?

  • Lifetime Qt Champion


    You can do the same kind of validation yes.

  • Sure, why not. You would probably connect the 'changed' signals from each of your TextWidgets and combobox to a slot that does basically the same checks you have in your wxWidgets code.

  • @SGaist - I didn't see a slot for it, so I guess I need to study on how to create one?

  • @mchinand - I see what you're saying.

  • @Driftwood

    A slot for what? I'm sure there is, no matter what you are going to answer (the default ones, of course).
    Custom behavior must be implemented depending on what you want to do with your text and widgets :)
    Like @mchinand said, a slot connected to the textChanged signal of every text field could work for you.
    You can check the content of textBoxes or comboBoxes and perform the rest of your actions. The syntax might change from wxWidgets to Qt.

    for example:


Log in to reply