首页 \ 问答 \ 当Activity启动时,EditText具有焦点,但不显示软键盘(EditText has focus when Activity starts, but soft keyboard is not shown)

当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 tried showSoftInput(yourTextBox, InputMethodManager.SHOW_IMPLICIT); and also requestFocus(). But no success...

What could be the problem?


原文:https://stackoverflow.com/questions/8128461
更新时间:2023-08-15 21:08

最满意答案

如果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_screentiming_screen ,如:

emit showPositionScreen_signal(position_screen);

正如thuga所指出的,这就是说你不需要两种不同的信号。 要将另一个QWidget传递到同一个插槽,只需用它发出该信号即可。 即:

emit showPositionScreen_signal(timing_screen);

我建议将信号的名称改为适当的名称。


If showScreen is declared as Qt Slot in your mainwindow.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 and timing_screen from within buttons_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.
  • 要使用新的连接语法,您必须将小部件转换为正确的类型。 例如: QPushButton b{“clear”}; QLineEdit e; QWidgetList widgets{&b, &e}; QObject::connect(qobject_cast(widgets[0]), &QPushButton::clicked, qobject_cast(widgets[1]), &QLineEdit::clear); 在设计 ...
  • 请参阅@ 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 ...
  • 问题是插槽中的代码: 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 ...
  • 一个简单的解决方案是创建我们自己的小部件,以便覆盖mouseDoubleClickEvent方法,并且可以覆盖paintEvent来绘制小部件: #ifndef DOUBLECLICKEDWIDGET_H #define DOUBLECLICKEDWIDGET_H #include #include class DoubleClickedWidget : public QWidget { Q_OBJECT public: explicit Dou ...
  • 您遇到的问题几乎可以肯定是由于没有重新创建moc文件,您在连接调用中输入错误或者在声明的插槽声明中输入错误。 您可能需要考虑从对话框获取输入所需的工作量远远超过必要的工作量。 更简单的方法是将“接受”按钮单击的信号连接到主窗口中的插槽,然后通过getXXX()方法直接从设置窗口的实例中获取所需的值。 如果最终有一个包含大量值的设置对话框,而不是通过getter获取每个值,则让“Accept”按钮信号返回一个结构,其中所有值都作为该结构的字段。 我应该提及它看起来像NewWindow()在每次调用时都会创建一 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。