当Activity启动时,EditText具有焦点,但不显示软键盘(EditText has focus when Activity starts, but soft keyboard is not shown)
如上所述,虽然EditText是聚焦的(橙色边框)并且光标闪烁,但键盘不会显示。 当我点击文本字段时,它会打开,但我希望它在活动开始时打开。
我试着在活动中设置
android:windowSoftInputMode="stateVisible"
,我试过showSoftInput(yourTextBox, InputMethodManager.SHOW_IMPLICIT);
还有requestFocus()
。 但没有成功......可能是什么问题呢?
as mentioned above, the keyboard does not show up, although the EditText is focused (orange border) and the cursor is blinking. When I click into text field, it opens up, however I want it to be open right when the activity starts.
I tried setting
android:windowSoftInputMode="stateVisible"
in the activity, I triedshowSoftInput(yourTextBox, InputMethodManager.SHOW_IMPLICIT);
and alsorequestFocus()
. But no success...What could be the problem?
原文:https://stackoverflow.com/questions/8128461
最满意答案
如果
showScreen
中声明为Qt Slot
,例如:private slots: void showScreen(QWidget* w);
并且您的信号在
buttons_widget
中声明signals: void showPositionScreen_signal(QWidget* w); //Note that signal needs same type as slot void showTimingScreen_signal(QWidget* w);
然后,您可以将该信号连接到插槽。 请注意,信号和插槽的参数必须匹配。 即: “信号和时隙机制是类型安全的:信号的签名必须与接收时隙的签名匹配。”实际上,一个时隙可能比它收到的信号具有更短的签名,因为它可以忽略额外的参数。“
connect(buttons_widget, SIGNAL(showPositionScreen_signal(QWidget*)), this, SLOT(showScreen(QWidget*)));
你必须从
timing_screen
发出position_screen
和timing_screen
,如:emit showPositionScreen_signal(position_screen);
正如thuga所指出的,这就是说你不需要两种不同的信号。 要将另一个
QWidget
传递到同一个插槽,只需用它发出该信号即可。 即:emit showPositionScreen_signal(timing_screen);
我建议将信号的名称改为适当的名称。
If
showScreen
is declared asQt Slot
in yourmainwindow.h
like:private slots: void showScreen(QWidget* w);
And your Signals are declared in
buttons_widget
signals: void showPositionScreen_signal(QWidget* w); //Note that signal needs same type as slot void showTimingScreen_signal(QWidget* w);
Then you can connect that signal to a slot. Note that the arguments of signals and slots have to match. I.e: "The signals and slots mechanism is type safe: The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)"
connect(buttons_widget, SIGNAL(showPositionScreen_signal(QWidget*)), this, SLOT(showScreen(QWidget*)));
And you will have to emit
position_screen
andtiming_screen
from withinbuttons_widget
like:emit showPositionScreen_signal(position_screen);
As thuga pointed out, it is to say that you do NOT need two different signals. To pass another
QWidget
to the same slot simply emit that signal with it. I.e.:emit showPositionScreen_signal(timing_screen);
And i would suggest to change the name of your signal to something appropriate then.
相关问答
更多-
您可以为每个单选按钮创建单独的包装插槽,然后将这些信息传递给您想要调用的功能。 像这样的东西: - class dialoginput : public QDialog { Q_OBJECT public: QRadioButton *radio1; QRadioButton *radio2; QRadioButton *radio3; private slots: void Radio1Selected() { setText_2(1); } void Ra ...
-
如果showScreen中声明为Qt Slot ,例如: private slots: void showScreen(QWidget* w); 并且您的信号在buttons_widget中声明 signals: void showPositionScreen_signal(QWidget* w); //Note that signal needs same type as slot void showTimingScreen_signal(QWidget* w); 然后,您可以 ...
-
使用类似的东西: QObject::connect(ui->Open, SIGNAL(clicked()), differentClass,SLOT(Slotindiffrentclass); Use something like: QObject::connect(ui->Open, SIGNAL(clicked()), differentClass,SLOT(Slotindiffrentclass);
-
pWidget是一个通用的QWidget。 它不包含方法/槽makeyourbox()。 你的代码有问题。 pWidget is a generic QWidget. It does not contain method/slot makeyourbox(). Your code is faulty.
-
从QWidgetList访问QWidget子插槽/信号(QList
)(Accessing QWidget child slots/signals from a QWidgetList (QList [2024-01-02])) 要使用新的连接语法,您必须将小部件转换为正确的类型。 例如: QPushButton b{“clear”}; QLineEdit e; QWidgetList widgets{&b, &e}; QObject::connect(qobject_cast(widgets[0]), &QPushButton::clicked, qobject_cast (widgets[1]), &QLineEdit::clear); 在设计 ... -
插槽上的装饰器(PyQt)(decorator on slot (PyQt))[2022-09-25]
请参阅@ ekhumoro对原因的解释,但在插槽中使用装饰的方法会由于签名不正确而导致您的问题。 import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * def LogInfos(func): def wrapper(*s, **gs): print('log') ret = func(*s, **gs) retur ... -
信号和插槽qt关闭插槽(signals and slots qt close slot)[2022-04-17]
问题是插槽中的代码: fenetre().close(); 。 这里fenetre()创建一个新的对象,在该对象上调用close() 。 所以只需在插槽中调用close() ,所有应该按照您的预期工作。 另外考虑使用Qt5风格连接函数指针,因为它们通常更安全,并且不要求使用头文件中的“插槽”标记函数: connect(button1, &QPushButton::clicked, this, &fenetre::another); The problem is the code in the slot: ... -
原因是,当发出QObject :: destroyed()时,派生类Subclass已经被销毁。 这是C ++破坏顺序所暗示的。 此外, 这个问题涉及类似的问题。 要解决这个问题,您可以使用C风格的指针转换(这是不相关的),或者重写代码以使用QObject。 The reason is that by the time QObject::destroyed() is emitted, your derived class Subclass has already been destroyed. This i ...
-
双击QWidget(QWidget with doubleclick)[2022-05-31]
一个简单的解决方案是创建我们自己的小部件,以便覆盖mouseDoubleClickEvent方法,并且可以覆盖paintEvent来绘制小部件: #ifndef DOUBLECLICKEDWIDGET_H #define DOUBLECLICKEDWIDGET_H #include#include class DoubleClickedWidget : public QWidget { Q_OBJECT public: explicit Dou ... -
QT:没有这样的插槽(QT: No Such Slot)[2022-06-08]
您遇到的问题几乎可以肯定是由于没有重新创建moc文件,您在连接调用中输入错误或者在声明的插槽声明中输入错误。 您可能需要考虑从对话框获取输入所需的工作量远远超过必要的工作量。 更简单的方法是将“接受”按钮单击的信号连接到主窗口中的插槽,然后通过getXXX()方法直接从设置窗口的实例中获取所需的值。 如果最终有一个包含大量值的设置对话框,而不是通过getter获取每个值,则让“Accept”按钮信号返回一个结构,其中所有值都作为该结构的字段。 我应该提及它看起来像NewWindow()在每次调用时都会创建一 ...