menu-example.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 427 行 · 第 1/2 页
HTML
427 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/examples/menu/menu.doc:4 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Using menus</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: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Using menus</h1> <p> This example demonstrates simple use of menus (a menu bar andpull-down menus). Qt also supports popup menus, although this exampledoesn't contain any.<p> <hr><p> Header file:<p> <pre>/****************************************************************************** $Id: qt/menu.h 3.0.5 edited Oct 12 2001 $**** 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 <a href="qwidget.html">QWidget</a>{ <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>public: 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 <a href="qstring.html">QString</a>& );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><p> <hr><p> Implementation:<p> <pre>/****************************************************************************** $Id: qt/menu.cpp 3.0.5 edited Jan 29 19:01 $**** 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 href="qpopupmenu-h.html">qpopupmenu.h</a>>#include <<a href="qapplication-h.html">qapplication.h</a>>#include <<a href="qmessagebox-h.html">qmessagebox.h</a>>#include <<a href="qpixmap-h.html">qpixmap.h</a>>#include <<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 <a href="qcustommenuitem.html">QCustomMenuItem</a>{public: MyMenuItem( const <a href="qstring.html">QString</a>& s, const <a href="qfont.html">QFont</a>& f ) : string( s ), font( f ){}; ~MyMenuItem(){} void paint( <a href="qpainter.html">QPainter</a>* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h ) { p-><a href="qpainter.html#setFont">setFont</a> ( font ); p-><a href="qpainter.html#drawText">drawText</a>( x, y, w, h, AlignLeft | AlignVCenter | DontClip, string ); } <a href="qsize.html">QSize</a> sizeHint() { return QFontMetrics( font ).size( AlignLeft | AlignVCenter | ShowPrefix | DontClip, string ); }private: <a href="qstring.html">QString</a> string; <a href="qfont.html">QFont</a> font;};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?