📄 menu-menu-cpp.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - menu/menu.cpp example file</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align=center>Using menus</h1><br clear="all"> This example demonstrates simple use of menus (a menu bar and pull-down menus). Qt also supports popup menus, but this example doesn't contain any. <blockquote> Customer: "My computer crashed!"<br> Tech Support: "It crashed?"<br> Customer: "Yeah, it won't let me play my game."<br> Tech Support: "All right, hit Control-Alt-Delete to reboot."<br> Customer: "No, it didn't crash -- it crashed."<br> Tech Support: "Huh?"<br> Customer: "I crashed my game. That's what I said before. I crashed my spaceship and now it doesn't work."<br> Tech Support: "Click on 'File,' then 'New Game.'"<br> Customer: [pause] "Wow! How'd you learn how to do that?"<br> </blockquote> Now you too can write menu trees tech support will know how to use! <hr> Header file: <pre>/****************************************************************************** $Id: qt/examples/menu/menu.h 2.3.8 edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#ifndef MENU_H#define MENU_H#include <<a href="qwidget-h.html">qwidget.h</a>>#include <<a href="qmenubar-h.html">qmenubar.h</a>>#include <<a href="qlabel-h.html">qlabel.h</a>>class MenuExample : public QWidget{ Q_OBJECTpublic: MenuExample( <a href="qwidget.html">QWidget</a> *parent=0, const char *name=0 );public slots: void open(); void news(); void save(); void closeDoc(); void undo(); void redo(); void normal(); void bold(); void underline(); void about(); void aboutQt(); void printer(); void file(); void fax(); void printerSetup();protected: void resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * );signals: void explain( const QString& );private: <a href="qmenubar.html">QMenuBar</a> *menu; <a href="qlabel.html">QLabel</a> *label; bool isBold; bool isUnderline; int boldID, underlineID;};#endif // MENU_H</pre> <hr> Implementation:<pre>/****************************************************************************** $Id: qt/examples/menu/menu.cpp 2.3.8 edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "menu.h"#include <<a name="qpopupmenu.h"></a><a href="qpopupmenu-h.html">qpopupmenu.h</a>>#include <qkeycode.h>#include <<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>>#include <<a name="qmessagebox.h"></a><a href="qmessagebox-h.html">qmessagebox.h</a>>#include <<a name="qpixmap.h"></a><a href="qpixmap-h.html">qpixmap.h</a>>#include <<a name="qpainter.h"></a><a href="qpainter-h.html">qpainter.h</a>>/* XPM */static const char * p1_xpm[] = {"16 16 3 1"," c None",". c #000000000000","X c #FFFFFFFF0000"," "," "," .... "," .XXXX. "," .............. "," .XXXXXXXXXXXX. "," .XXXXXXXXXXXX. "," .XXXXXXXXXXXX. "," .XXXXXXXXXXXX. "," .XXXXXXXXXXXX. "," .XXXXXXXXXXXX. "," .XXXXXXXXXXXX. "," .XXXXXXXXXXXX. "," .XXXXXXXXXXXX. "," .............. "," "};/* XPM */static const char * p2_xpm[] = {"16 16 3 1"," c None",". c #000000000000","X c #FFFFFFFFFFFF"," "," ...... "," .XXX.X. "," .XXX.XX. "," .XXX.XXX. "," .XXX..... "," .XXXXXXX. "," .XXXXXXX. "," .XXXXXXX. "," .XXXXXXX. "," .XXXXXXX. "," .XXXXXXX. "," .XXXXXXX. "," ......... "," "," "};/* XPM */static const char * p3_xpm[] = {"16 16 3 1"," c None",". c #000000000000","X c #FFFFFFFFFFFF"," "," "," ......... "," ........... "," ........ .. "," ........... "," ........... "," ........... "," ........... "," ...XXXXX... "," ...XXXXX... "," ...XXXXX... "," ...XXXXX... "," ......... "," "," "};/* Auxiliary class to provide fancy menu items with different fonts. Used for the "bold" and "underline" menu items in the options menu. */class MyMenuItem : public QCustomMenuItem{public: MyMenuItem( const QString& s, const QFont& f ) : string( s ), font( f ){};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -