Qt的dialog中lineedit无法输入

背景:继承修改Qt的Qdialog,框内添加了一下lineedit,但是发现焦点也抓到了,软键盘也弹出了,就是不能输入字符。


先找原因,因为是使用的模态对话框,最后有执行exec(),所以查看Qt的帮助文档怎么介绍exec()的。

[virtual slot] int QDialog::exec()
Shows the dialog as a modal dialog, blocking until the user closes it. The function returns a DialogCode result.
If the dialog is application modal, users cannot interact with any other window in the same application until they close the dialog. If the dialog is window modal, only interaction with the parent window is blocked while the dialog is open. By default, the dialog is application modal.
See also open(), show(), result(), and setWindowModality().

大意就是说这是方法是用来关闭对话框的,并且会返回结果。如果是应用模式情况下,那么在关闭对话框之前是不能与任何的同一个程序中的任意窗口进行交互的。如果是窗口模式,仅阻止与父窗口交互。并且默认情况下是应用模式。


那可能是模式上的选择造成的,那模式又有几种呢?

windowModality : Qt::WindowModality
This property holds which windows are blocked by the modal widget
This property only makes sense for windows. A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must hide() the widget first, then show() it again.
By default, this property is Qt::NonModal.
This property was introduced in Qt 4.1.
Access functions:

Qt::WindowModality 
windowModality() const
void 
setWindowModality(Qt::WindowModality windowModality)

See also isWindow(), QWidget::modal, and QDialog.

这个意思是说,这个属性设置就是用来保持哪些窗口小部件被模态窗口阻止了,模态窗口的小部件可以防止其他窗口的小部件或的输入。


那就明白了,默认是应用模式,那设置为WindowModal就可以了。

InputDailog myInputDailog;
myInputDailog.setWindowModality(Qt::WindowModal);
myInputDailog.exec();
发布了149 篇原创文章 · 获赞 164 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/baidu_33879812/article/details/105265123