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. QWidget slots and focus
Forum Updated to NodeBB v4.3 + New Features

QWidget slots and focus

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 862 Views 3 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.
  • B Offline
    B Offline
    Bert59
    wrote on last edited by
    #1

    Hi,
    I'm a beginner with Qt and therefore have some basic questions.

    I have made a very simple test program to demonstrate my issue.

    20dfe011-97e0-46d5-81d1-107d5640fbf2-image.png

    If I click on the button "Set Text 1" the text "Test push button" is displayed in the lineEdit "Text1".

    If I enter a text in "Text input" I copy this text into "Text Copy"

    fef49c86-fe20-4454-b410-0f5ceb3a7dc7-image.png

    The behavior I don't understand is that when I enter a text in "Text input" and hit the enter key it fires also the pushButton slot and the text in "Text 1" is also displayed witout clicking on the button.

    The related question is: Why if the focus is on Text input it remains also on the button?

    Here is the code of the slots:

    void MyDialog::on_setText1_clicked()
    {
    ui->lineEdit->setText("Test push button");
    }

    void MyDialog::on_textInput_editingFinished()
    {
    QString m_text = ui->textInput->text();
    ui->textCopy->setText(m_text);
    }

    Thank you

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

      Hi,

      What version of Qt ?
      On what OS ?
      Can you show the whole code you are using ?
      Maybe provide a minimal compilable example that shows the behaviour ?

      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
      • B Offline
        B Offline
        Bert59
        wrote on last edited by
        #3

        Hi and thank you for taking a look at my issue or my lack of knomledge about Qt.
        I'm using Qt with Windows 10
        I'm using
        49e605a3-885e-48a3-a8fd-c942a5b42ddd-image.png

        The complete test project can be downloaded from the link below
        https://www.dropbox.com/s/pb9usnmp6jxb312/MainWindow1.zip?dl=0
        Regards

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

          These are the information about Qt Creator.

          What version of Qt are you using to build your project ?

          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
          • B Offline
            B Offline
            Bert59
            wrote on last edited by
            #5

            I think its Qt 5.14.2.
            How can I get this information for sure?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              Bert59
              wrote on last edited by
              #6

              Yes it is Qt 5.14.2
              54df24e6-2f0e-4b5e-8910-e7f577790ad9-image.png

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

                It's defined in the Kit you are using to build your application.

                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
                • B Bert59

                  Hi,
                  I'm a beginner with Qt and therefore have some basic questions.

                  I have made a very simple test program to demonstrate my issue.

                  20dfe011-97e0-46d5-81d1-107d5640fbf2-image.png

                  If I click on the button "Set Text 1" the text "Test push button" is displayed in the lineEdit "Text1".

                  If I enter a text in "Text input" I copy this text into "Text Copy"

                  fef49c86-fe20-4454-b410-0f5ceb3a7dc7-image.png

                  The behavior I don't understand is that when I enter a text in "Text input" and hit the enter key it fires also the pushButton slot and the text in "Text 1" is also displayed witout clicking on the button.

                  The related question is: Why if the focus is on Text input it remains also on the button?

                  Here is the code of the slots:

                  void MyDialog::on_setText1_clicked()
                  {
                  ui->lineEdit->setText("Test push button");
                  }

                  void MyDialog::on_textInput_editingFinished()
                  {
                  QString m_text = ui->textInput->text();
                  ui->textCopy->setText(m_text);
                  }

                  Thank you

                  M Offline
                  M Offline
                  mpergand
                  wrote on last edited by
                  #8

                  @Bert59 said in QWidget slots and focus:

                  The behavior I don't understand is that when I enter a text in "Text input" and hit the enter key it fires also the pushButton slot

                  Hi,

                  Because your button is the default one of the dialog.
                  Very common issue, see Here

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    Bert59
                    wrote on last edited by
                    #9

                    Hi
                    I think I found a solution.
                    When adding a push button in the Designer, it is by default set to autoDefault.
                    If I uncheck this property for all push buttons I get the expected behavior

                    03e443f9-7e1b-470d-8225-9d6ad1121468-image.png

                    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