QPlainTextEdit 上的 Qt 代码编辑器 如何选项卡代码

发布于 2024-10-08 23:33:11 字数 391 浏览 0 评论 0原文

我正在尝试实现一个简单的对话框来编辑代码的某些部分。我使用基于 QPlainTextEdit 的 this 。但是,我无法将制表符插入代码文本中。主要原因可能是我将代码编辑器显示为代码中所示的对话框。当我按 Tab 按钮时,对话框将关闭然后重新打开。

CodeEditor* editor = new CodeEditor(this);
editor->setWindowFlags(Qt::Dialog);
editor->setMinimumSize(400, 400);
editor->show();

I am trying to implement a simple dialog to edit some part of code. I use this which is based on QPlainTextEdit. However, I cannot insert tab into code text. The main reason could be that I show the Code editor as dialog as seen in the code. When I press Tab button the dialog closes and then reopens.

CodeEditor* editor = new CodeEditor(this);
editor->setWindowFlags(Qt::Dialog);
editor->setMinimumSize(400, 400);
editor->show();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无边思念无边月 2024-10-15 23:33:11

谢谢大家,

我解决了问题,这完全是关于我在问题中没有提到的部分。此代码是 qtpropertybrowser 代码库的一部分。我正在尝试添加一个属性编辑器,它将打开我在问题中指出的代码编辑小部件。当我深入qt属性代码库时,我发现tab键被忽略了,因为它被eventFilter过滤了。当我改变这部分的时候。我解决了这个问题。

但是,我无法解决编辑器关闭并重新打开的问题。变得这么快。并且输出错误消息如下 QWidget::setTabOrder: 'first' 和 'second' 必须在同一窗口中。

Thanks guys,

I solved the problem and it is totally about the part I did not mention in the question. This code is part of qtpropertybrowser code base. I am trying to add a property editor which will open code editing widget I pointed out in the question. When I drill down the qt property code base, I found that tab key is neglected because, it is filtered by eventFilter. When I change this part. I solved the problem.

but, I couldn't solve the problem that the editor is closed and reopened. It becomes so quick. And and error message is outputted as follows QWidget::setTabOrder: 'first' and 'second' must be in the same window.

梦初启 2024-10-15 23:33:11

尝试使用 Qt::Window 而不是 Qt::Dialog 并使用 QWidget::setWindowModality() 使其成为应用程序模式。

Try using Qt::Window instead of Qt::Dialog and make it application modal by using QWidget::setWindowModality().

风轻花落早 2024-10-15 23:33:11

我会将编辑器嵌入到带有“确定”和“取消”按钮的 QDialog 中。另外,请确保 QPlainTextEdit::tabChangesFocus() 为 false。

I would embed the editor in a QDialog with OK and Cancel buttons. Also, make sure that QPlainTextEdit::tabChangesFocus() is false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文