Not reading keyboard input after Pop-Up closes
-
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(); } -
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. -
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 jakubd has marked this topic as solved on
-
You could make that dialog a small class. It would make it self-contained and easier to use.
-
Well, first thing: do you really need to call grabKeyboard ? Why not just set the focus on the line edit ?