QT Menu how to create a new window?

有些话、适合烂在心里 提交于 2019-12-18 09:43:29

问题


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


回答1:


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.




回答2:


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.

  1. Default mainwindow.cpp

  1. Go to "mainwindow.ui" (or whatever .ui one has)

  1. Right-click outside the window and activate "Action Editor" if it wasn't already activated:

  1. Right-click on the window and create "Menu-bar" and then double-clicking on "type here" you can rename it as "Open" or something which will then drop-down another box where you can again type the name you desire, let's say "message".

  1. When created menu item "message" is created corresponding item will apear in the "Action Editor"

  1. Right-click on the "message" in the Action Editor and click "go to slot" which will lead you to the specific slot in the mainwindow.cpp:

  1. Here you can create a small window with whatever message you want to display.

[![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 :



来源:https://stackoverflow.com/questions/6743970/qt-menu-how-to-create-a-new-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!