QT菜单如何创建新窗口?
我在 QT Creator 工作。
我想说我是这个软件的初学者。我成功创建了一个菜单,其中包含:编辑和打开。我想在单击菜单栏中的“打开”时创建一个新窗口。到目前为止,当我按“打开”时,我成功地在 QMessageBox 中打印了一条消息。用新窗口链接“打开”的代码是什么?是否可以以某种方式在 mainwindow.ui 中拖放一个新窗口,然后将其与 Open_activated() 操作上的“打开”链接?
谢谢 。欣赏
P.SI AM 在 UBUNTU/C++ 语言中工作
I am working in QT Creator.
I would like to mention that I am beginner in this software. I succeeded to create a menu that has: Edit and Open. I would like to create a new window when " Open " from menu bar is clicked. Till now I succeeded to print a message in QMessageBox when I press Open. What is the code for linking Open clicked with a new window? Is it possible to somehow drag and drop a new window in mainwindow.ui and than link it with Open on action Open_activated()?
THX . Appreciate
P.S I AM WORKING IN UBUNTU/C++ language
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能已经太晚了,但由于我也是一个初学者,并且为了弄清楚这一点付出了很多努力,我想分享一个对我有用的解决方案,根据我的说法,这是对于初学者来说最简单的解决方案之一。
请点击此链接。将来这个链接可能不存在,因此我正在写下一个详细的版本,尽可能详细,因为我认为对于绝对的初学者(像我自己)来说它可能非常有用。
[![创建代码的窗口]11 等在这里。]12
*** *不忘记包含“QTextEditor”,请转到 mainwindow.h 和 #include "
在编译和执行时我们将看到:
This is probably too late to answer but as I am also a beginner and struggled a lot to figure out this, I would like to share a solution that worked for me and according to me this is one of the simplest solution out there for a beginner.
Follow this link. It's possible that in the future that link might not exists, hence I am writing down a detailed version, as detailed as possible because I think for an absolute beginner (like myself) it can be very useful.
[![Window creating code]11 etc goes here.]12
****don't forget to include "QTextEditor", go to mainwindow.h and #include "
On compiling & executing we will see :
上一个问题。它留下了一部分开放,即该插槽的调用方式。
好吧,您的回答是:菜单项“打开”是一个
QAction
。您可以将该操作连接到该插槽您刚刚创建的。Most of the question is already answered by this previous question. It leaves one part open, namely how that slot is called.
Well, you answered that: the menu entry "Open" is a
QAction
. You can connect that action to the slot which you just created.