Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] QInputDialog - change Cancel button text
Forum Updated to NodeBB v4.3 + New Features

[solved] QInputDialog - change Cancel button text

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 7.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    matobodo
    wrote on last edited by
    #1

    i have here a code to display inptut dialog, what should i add to change Cancel button text?
    @
    bool ok = false;
    QString input = QInputDialog::getText(0,Strings::uasNewUser,Strings::uasLoginName,QLineEdit::Normal,"",&ok);
    if (ok) {
    if (input != "") {
    bool insert = true;
    Sql sql;
    if (sql.connect()) {
    usernames = sql.getUsernames();
    for (int i = 0; i < usernames.length(); ++i) {
    if (usernames[i] == input) insert = false;
    }
    if (insert) {
    sql.insertUser(input);
    loadData();
    showUserData(ui->users->count()-1);
    } else {
    QMessageBox::warning(0,Strings::uasUserExist,Strings::uasUserWithName + " '"+input+"' "+ Strings::uasExist );
    }
    }
    } else {
    QMessageBox::warning(0,Strings::uasEmptyUsernameTitle,Strings::uasEmptyUsername);
    }
    }@

    1 Reply Last reply
    0
    • musimbateM Offline
      musimbateM Offline
      musimbate
      wrote on last edited by
      #2

      Hi,
      One way I see around this is to create your QInputDialog with the constructor and call
      @setCancelButtonText()@

      on it.

      Why join the navy if you can be a pirate?-Steve Jobs

      1 Reply Last reply
      0
      • M Offline
        M Offline
        matobodo
        wrote on last edited by
        #3

        @
        QInputDialog inputDialog;
        inputDialog.setInputMode(QInputDialog::TextInput);
        inputDialog.setCancelButtonText("My text");@
        how will i know that OK button was clicked?
        how can i show the input dialog?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Using exec and checking its return value

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            matobodo
            wrote on last edited by
            #5

            @bool ok = inputDialog.exec();@
            the exec() function will return true if OK button was clicked
            and this
            @QString returnString = inputDialog.textValue();@
            will return the text writen by user

            is it correct?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              exec doesn't return a boolean value, it's a QDialog::DialogCode which can be in this case mapped to a boolean value.

              For the second part, yes.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • M Offline
                M Offline
                matobodo
                wrote on last edited by
                #7

                ok thanks i have solved my problem

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You're welcome !

                  Since you have all running now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved