📄 my_widget.cpp.html
字号:
<HTML><HEAD><TITLE>my_widget.cpp.html</TITLE></HEAD><BODY BGCOLOR=#FFFFFF TEXT=#000000><PRE><FONT COLOR=#a020f0>#include </FONT><FONT COLOR=#ff00ff><iostream></FONT>using namespace std;<FONT COLOR=#a020f0>#include </FONT><FONT COLOR=#ff00ff>"my_widget.h"</FONT><FONT COLOR=#008b8b>MyMainWindow::MyMainWindow</FONT>(QWidget* parent, <B><FONT COLOR=#2e8b57>const</FONT></B> <B><FONT COLOR=#2e8b57>char</FONT></B>* name):QMainWindow(parent, name){ CreateMenu(); <FONT COLOR=#5151fb>// create a button</FONT> buttonExit = <B><FONT COLOR=#853e26>new</FONT></B> QPushButton(<FONT COLOR=#ff00ff>"Exit"</FONT>, <B><FONT COLOR=#853e26>this</FONT></B>, <FONT COLOR=#ff00ff>0</FONT>); buttonExit->setGeometry(<FONT COLOR=#ff00ff>60</FONT>, <FONT COLOR=#ff00ff>60</FONT>, <FONT COLOR=#ff00ff>100</FONT>, <FONT COLOR=#ff00ff>40</FONT>); <FONT COLOR=#5151fb>// connect the "clicked" signal of the QPushButton buttonExit</FONT> <FONT COLOR=#5151fb>// to the "OnExit()" slot of this MyMainWindow object.</FONT> <FONT COLOR=#5151fb>// So, if buttonExit is clicked, this->OnExit() will be called.</FONT> QObject::connect(buttonExit, SIGNAL(clicked()), <B><FONT COLOR=#853e26>this</FONT></B>, SLOT(OnExit())); <FONT COLOR=#5151fb>// PS: connect() is a static member function of QObject.</FONT>}<B><FONT COLOR=#2e8b57>void</FONT></B> MyMainWindow::CreateMenu(){ QPopupMenu* file = <B><FONT COLOR=#853e26>new</FONT></B> QPopupMenu(<B><FONT COLOR=#853e26>this</FONT></B>); <FONT COLOR=#5151fb>// this MyMainWindow object's OnTesting slot/function</FONT> <FONT COLOR=#5151fb>// will be called if "Testing" menu item is clicked.</FONT> file->insertItem(<FONT COLOR=#ff00ff>"Testing"</FONT>, <B><FONT COLOR=#853e26>this</FONT></B>, SLOT(OnTesting())); file->insertItem(<FONT COLOR=#ff00ff>"Exit"</FONT>, <B><FONT COLOR=#853e26>this</FONT></B>, SLOT(OnExit())); menuBar()->insertItem(<FONT COLOR=#ff00ff>"File"</FONT>, file); QPopupMenu* help = <B><FONT COLOR=#853e26>new</FONT></B> QPopupMenu(<B><FONT COLOR=#853e26>this</FONT></B>); help->insertItem(<FONT COLOR=#ff00ff>"About"</FONT>, <B><FONT COLOR=#853e26>this</FONT></B>, SLOT(OnAbout())); menuBar()->insertItem(<FONT COLOR=#ff00ff>"Help"</FONT>, help);}<B><FONT COLOR=#2e8b57>void</FONT></B> MyMainWindow::OnTesting(){ QString caption(<FONT COLOR=#ff00ff>"Testing"</FONT>); QString text(<FONT COLOR=#ff00ff>"Testing is clicked."</FONT>); <FONT COLOR=#5151fb>// prompt a modal dialog</FONT> QMessageBox::information(<B><FONT COLOR=#853e26>this</FONT></B>, caption, text, QMessageBox::Ok); cout << <FONT COLOR=#ff00ff>"You could also use cout here! "</FONT> << endl;}<B><FONT COLOR=#2e8b57>void</FONT></B> MyMainWindow::OnExit(){ <FONT COLOR=#5151fb>// qApp is a global pointer points to</FONT> <FONT COLOR=#5151fb>// our application object (QApplication)</FONT> qApp->quit(); <FONT COLOR=#5151fb>// quit this application program</FONT>}<B><FONT COLOR=#2e8b57>void</FONT></B> MyMainWindow::OnAbout(){ QMessageBox::about(<B><FONT COLOR=#853e26>this</FONT></B>, <FONT COLOR=#ff00ff>"About"</FONT>, <FONT COLOR=#ff00ff>"Type something here..."</FONT>);}</PRE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -