简体   繁体   English

qt5捕获来自qtextedit的输入

[英]qt5 catch input from qtextedit

I am working on a small application which is basically a serial terminal with some added stuff. 我正在开发一个小型应用程序,该应用程序基本上是带有一些附加内容的串行终端。

for the terminal window I use the QTextEdit widget and allready overload add and overload some methods. 对于终端窗口,我使用QTextEdit小部件,并准备好重载添加和重载某些方法。 However since this is a serial terminal I don't want the input that the user is typing in the QTextEdit to actually end up there. 但是,由于这是一个串行终端,所以我不希望用户在QTextEdit键入的输入实际在此结束。 Most serial communication channels echo back the input that is send to them and I would like to show this in the QTextEdit and not what the user inputs. 大多数串行通信通道回显发送给他们的输入,我想在QTextEdit显示此内容,而不是用户输入的内容。

The ideal would be I could overload the way QTextEdit handles its input and I work from there. 理想的做法是,我可以重载QTextEdit处理其输入的方式,然后从那里开始工作。

I have looked online but I can't seem to find what I am looking for. 我在网上看过,但似乎找不到我想要的东西。 Maybe I am using the wrong search terms 也许我使用了错误的搜索词

You can set the QTextEdit widget to read-only mode and then just listen for its key events. 您可以将QTextEdit小部件设置为只读模式,然后仅侦听其关键事件。 That way nothing will be displayed in the QTextEdit and you will be able to intercept the keys. 这样, QTextEdit中将不会显示任何内容,并且您将能够截获这些键。

If you subclass QTextEdit and reimplement the keyPressevent , you might want to call the base class implementation inside it. 如果将QTextEdit子类化并重新实现keyPressevent ,则可能要在其中调用基类实现。 Otherwise you might not get the functionalities that for example page-up/page-down keys provide. 否则,您可能无法获得例如上一页/下一页键所提供的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM