Custom QWidget Keyboard first time click issue.
-
Hi,
from my experience, this behaviour comes from the focus shift,
you click a button and than it gets the focus a and only than the clicked mechanimn works.
IIRC, you can change that a couple of different ways.
the following comes to my mind:
- Chaning the signal from clicked to released
- Subclassing QPushButton and manually emitting the pressed signal during focus in event
-
Hi,
from my experience, this behaviour comes from the focus shift,
you click a button and than it gets the focus a and only than the clicked mechanimn works.
IIRC, you can change that a couple of different ways.
the following comes to my mind:
- Chaning the signal from clicked to released
- Subclassing QPushButton and manually emitting the pressed signal during focus in event
-
Thank you for your reply.
- At the first time my Push button click event is not getting fired so released event is also not working.
- I have implemented focus in event but at first time its also not getting emitting.
-
It may be a silly question, does it happen with all the buttons of your keyboard?
Are you sure that the first time you push on a button of your keyboard the slot keyboardHandler() gets called? -
It may be a silly question, does it happen with all the buttons of your keyboard?
Are you sure that the first time you push on a button of your keyboard the slot keyboardHandler() gets called?@JoZCaVaLLo
Yes, it happens with all the buttons of a keyboard. slot keyboardHandler() does not get called for the first time. another thing I observed that when I called a keyboard on QPushbutton clicked event then keyboard works properly. this issue happens with QlineEdit Only.
-
I would call lineEditkeyboard->setLineEdit(line) only when the lineEdit gets the focus.
In addition, in the setLineEdit(), I would call this->setFocusProxy(line). In order to avoid your keyboard to steal the focus from your linedit. -
I would call lineEditkeyboard->setLineEdit(line) only when the lineEdit gets the focus.
In addition, in the setLineEdit(), I would call this->setFocusProxy(line). In order to avoid your keyboard to steal the focus from your linedit.@JoZCaVaLLo
@mrjj
@J-Hilk
@dheerendra
one more thing to share when I called keyboard widget with a show() like
lineEditkeyboard->setLineEdit(line);
lineEditkeyboard->show();the keyboard works properly but when I called Keyboard like
lineEditkeyboard->setLineEdit(line);
lineEditkeyboard->setWindowModality(Qt::ApplicationModal);
lineEditkeyboard->show();then I face the same issue of the first click.
-
@JoZCaVaLLo
@mrjj
@J-Hilk
@dheerendra
one more thing to share when I called keyboard widget with a show() like
lineEditkeyboard->setLineEdit(line);
lineEditkeyboard->show();the keyboard works properly but when I called Keyboard like
lineEditkeyboard->setLineEdit(line);
lineEditkeyboard->setWindowModality(Qt::ApplicationModal);
lineEditkeyboard->show();then I face the same issue of the first click.
@Arvind-K
hi, we need to find out what is happening.
please do
qDebug() << "focus widget " << qApp->focusObject();
which tells us when you open the keyboard, who has focus.
Meaning who will get the keys if u type.
I think you have something that steals keyboard focus when u open the
lineEditkeyboard -
@Arvind-K
hi, we need to find out what is happening.
please do
qDebug() << "focus widget " << qApp->focusObject();
which tells us when you open the keyboard, who has focus.
Meaning who will get the keys if u type.
I think you have something that steals keyboard focus when u open the
lineEditkeyboard -
as you said I have done same when keyboard widget is shown.
output isDBG default: focus widget QLineEdit(0x227ca90, name = "lineEdit")
lineEdit is Nothing but the QLineEdit on Keyboard widget.
-
Yes.
after that when I click on Anywhere on Widget Nothing happen or no Any event gets called. -
@Arvind-K
so the widget appear frozen for a moment ?
Do you have any kind of loops in constructor or anything like that ?No, there is no Loop in the constructor or No Any other code only I have connected signal to Slot.
Keyboard::Keyboard(QWidget *parent) :
QWidget(parent),
ui(new Ui::Keyboard)
{
ui->setupUi(this);this->setWindowFlags(Qt::WindowStaysOnTopHint); connect ( ui->Buttonq, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonw, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttone, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonr, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttont, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttony, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonu, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttoni, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttono, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonp, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttona, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttons, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttond, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonf, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttong, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonh, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonj, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonk, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonl, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonz, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonx, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonc, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonv, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonb, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonn, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonm, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button0, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button1, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button2, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button3, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button4, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button5, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button6, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button7, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button8, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button9, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->space, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); outputText = ""; shift = false;
}
-
No, there is no Loop in the constructor or No Any other code only I have connected signal to Slot.
Keyboard::Keyboard(QWidget *parent) :
QWidget(parent),
ui(new Ui::Keyboard)
{
ui->setupUi(this);this->setWindowFlags(Qt::WindowStaysOnTopHint); connect ( ui->Buttonq, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonw, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttone, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonr, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttont, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttony, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonu, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttoni, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttono, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonp, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttona, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttons, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttond, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonf, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttong, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonh, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonj, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonk, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonl, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonz, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonx, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonc, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonv, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonb, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonn, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Buttonm, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button0, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button1, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button2, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button3, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button4, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button5, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button6, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button7, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button8, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->Button9, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); connect ( ui->space, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) ); outputText = ""; shift = false;
}
-
As I mentioned Previously when I set WindowModality of Keyboard widget to QApplicationModal I face this First Click issue otherwise it works fine. but if I didn't set windowModality then Keyboard goes back to the parent widget.
**lineEditkeyboard->setWindowModality(Qt::ApplicationModal); **
-
As I mentioned Previously when I set WindowModality of Keyboard widget to QApplicationModal I face this First Click issue otherwise it works fine. but if I didn't set windowModality then Keyboard goes back to the parent widget.
**lineEditkeyboard->setWindowModality(Qt::ApplicationModal); **
Hmm.
The code looks ok fine and i cant see any reason for
QApplicationModal to cause this effect but
it could be a bug in Qt. -
@Arvind-K
ok. when this situation is happening.
Does the buttons show activated effect ?
I mean can u see u pres them or anything ? -
@Arvind-K
Ok, then it seems its stuck for a moment in the event loop.
Im not sure what to do about that.
setWindowModality(Qt::ApplicationModal) must use a local even loop to make
it modal so might be a but with this or something i dont see in the code.