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. Not reading keyboard input after Pop-Up closes
Qt 6.11 is out! See what's new in the release blog

Not reading keyboard input after Pop-Up closes

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 375 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.
  • J Offline
    J Offline
    jakubd
    wrote on last edited by
    #1

    Hey,
    I have an issue I can't seem to solve. In my application I create a pop-up window using QWidget. It shows up fine, accepts keyboard no problem. I connected a button. the reminder of the code doesn't really matter, saves data - that's all. But I want the button to close the pop-up, which also works 100% correctly. My issue is that when it closes, comes back to where the app were before the pop-up, I can't seem to be able to input anything to QLineEdits in the displayed window from the keyboard (that previously worked). I tried resetting them by using qLineEditName.setRealOnly(false); or even qLineEditName.setAcceptDrops(true);
    It's all in c++ obv.
    Honestly, no clue what I'm missing.

    P.S. I know making a global variable is a big no-no in regards to the esthetics of the code but hopefully it can be forgiven :)

    QWidget* popUpNewTime;
    QTimeEdit* timeChoicePopUP;
    QPushButton *button1;
    void edit::on_addTime_clicked() {
    
        //Creating pop-up with time choice and a save button
        popUpNewTime = new QWidget(this, Qt::Popup);
        popUpNewTime->setWindowModality(Qt::WindowModal);
        QRect rect = QStyle::alignedRect(layoutDirection(), Qt::AlignBottom, QSize(width()/4, height()/6), geometry());
        popUpNewTime->setGeometry(rect);
    
        QVBoxLayout* layout = new QVBoxLayout(popUpNewTime);
    
        timeChoicePopUP = new QTimeEdit();
        button1 = new QPushButton("SAVE");
    
        layout->addWidget(timeChoicePopUP);
        layout->addWidget(button1);
        timeChoicePopUP->activateWindow();
        timeChoicePopUP->grabKeyboard();
        popUpNewTime->show();
    
        connect(button1,&QPushButton::clicked,this, &edit::addingTime);
    
    }
    void edit::addingTime() {
       timeChoicePopUP->close();
        button1->close();
        popUpNewTime->close();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One thing that comes to mind: you never release the keyboard.
      Note that you are also leaking memory because closing a widget does not mean it gets deleted.
      By the way, it's not a question of esthetics, global variables are a bad idea most of the time but always in the case you are showing.

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

      J 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        One thing that comes to mind: you never release the keyboard.
        Note that you are also leaking memory because closing a widget does not mean it gets deleted.
        By the way, it's not a question of esthetics, global variables are a bad idea most of the time but always in the case you are showing.

        J Offline
        J Offline
        jakubd
        wrote on last edited by
        #3

        @SGaist Thank you! it worked! Also, i fugured out how to do it without global variables. I didnt know how to use connect so i can declare the function within that call. From now on, no more global variables ;)

        1 Reply Last reply
        0
        • J jakubd has marked this topic as solved on
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You could make that dialog a small class. It would make it self-contained and easier to use.

          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
          • thomaseT Offline
            thomaseT Offline
            thomase
            Banned
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Well, first thing: do you really need to call grabKeyboard ? Why not just set the focus on the line edit ?

              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