1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/menu/menu.doc:4 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Using menus</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <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>
|
---|
33 |
|
---|
34 |
|
---|
35 | <p>
|
---|
36 | This example demonstrates a menu bar with pull-down menus,
|
---|
37 | sub-menus and custom menu items. It also demonstrates a pop-up
|
---|
38 | context menu.
|
---|
39 | <p> <hr>
|
---|
40 | <p> Header file:
|
---|
41 | <p> <pre>/****************************************************************************
|
---|
42 | ** $Id: menu-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
43 | **
|
---|
44 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
45 | **
|
---|
46 | ** This file is part of an example program for Qt. This example
|
---|
47 | ** program may be used, distributed and modified without limitation.
|
---|
48 | **
|
---|
49 | *****************************************************************************/
|
---|
50 |
|
---|
51 | #ifndef MENU_H
|
---|
52 | #define MENU_H
|
---|
53 |
|
---|
54 | #include <<a href="qwidget-h.html">qwidget.h</a>>
|
---|
55 | #include <<a href="qmenubar-h.html">qmenubar.h</a>>
|
---|
56 | #include <<a href="qlabel-h.html">qlabel.h</a>>
|
---|
57 |
|
---|
58 |
|
---|
59 | class MenuExample : public <a href="qwidget.html">QWidget</a>
|
---|
60 | {
|
---|
61 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
---|
62 | public:
|
---|
63 | MenuExample( <a href="qwidget.html">QWidget</a> *parent=0, const char *name=0 );
|
---|
64 |
|
---|
65 | public slots:
|
---|
66 | void open();
|
---|
67 | void news();
|
---|
68 | void save();
|
---|
69 | void closeDoc();
|
---|
70 | void undo();
|
---|
71 | void redo();
|
---|
72 | void normal();
|
---|
73 | void bold();
|
---|
74 | void underline();
|
---|
75 | void about();
|
---|
76 | void aboutQt();
|
---|
77 | void printer();
|
---|
78 | void file();
|
---|
79 | void fax();
|
---|
80 | void printerSetup();
|
---|
81 |
|
---|
82 | protected:
|
---|
83 | void resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * );
|
---|
84 |
|
---|
85 | signals:
|
---|
86 | void explain( const <a href="qstring.html">QString</a>& );
|
---|
87 |
|
---|
88 | private:
|
---|
89 | void contextMenuEvent ( <a href="qcontextmenuevent.html">QContextMenuEvent</a> * );
|
---|
90 |
|
---|
91 |
|
---|
92 | <a href="qmenubar.html">QMenuBar</a> *menu;
|
---|
93 | <a href="qlabel.html">QLabel</a> *label;
|
---|
94 | bool isBold;
|
---|
95 | bool isUnderline;
|
---|
96 | int boldID, underlineID;
|
---|
97 | };
|
---|
98 |
|
---|
99 |
|
---|
100 | #endif // MENU_H
|
---|
101 | </pre>
|
---|
102 |
|
---|
103 | <p> <hr>
|
---|
104 | <p> Implementation:
|
---|
105 | <p> <pre>/****************************************************************************
|
---|
106 | ** $Id: menu-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
107 | **
|
---|
108 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
109 | **
|
---|
110 | ** This file is part of an example program for Qt. This example
|
---|
111 | ** program may be used, distributed and modified without limitation.
|
---|
112 | **
|
---|
113 | *****************************************************************************/
|
---|
114 |
|
---|
115 | #include "menu.h"
|
---|
116 | #include <<a href="qcursor-h.html">qcursor.h</a>>
|
---|
117 | #include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>
|
---|
118 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
119 | #include <<a href="qmessagebox-h.html">qmessagebox.h</a>>
|
---|
120 | #include <<a href="qpixmap-h.html">qpixmap.h</a>>
|
---|
121 | #include <<a href="qpainter-h.html">qpainter.h</a>>
|
---|
122 |
|
---|
123 | /* XPM */
|
---|
124 | static const char * p1_xpm[] = {
|
---|
125 | "16 16 3 1",
|
---|
126 | " c None",
|
---|
127 | ". c #000000000000",
|
---|
128 | "X c #FFFFFFFF0000",
|
---|
129 | " ",
|
---|
130 | " ",
|
---|
131 | " .... ",
|
---|
132 | " .XXXX. ",
|
---|
133 | " .............. ",
|
---|
134 | " .XXXXXXXXXXXX. ",
|
---|
135 | " .XXXXXXXXXXXX. ",
|
---|
136 | " .XXXXXXXXXXXX. ",
|
---|
137 | " .XXXXXXXXXXXX. ",
|
---|
138 | " .XXXXXXXXXXXX. ",
|
---|
139 | " .XXXXXXXXXXXX. ",
|
---|
140 | " .XXXXXXXXXXXX. ",
|
---|
141 | " .XXXXXXXXXXXX. ",
|
---|
142 | " .XXXXXXXXXXXX. ",
|
---|
143 | " .............. ",
|
---|
144 | " "};
|
---|
145 |
|
---|
146 | /* XPM */
|
---|
147 | static const char * p2_xpm[] = {
|
---|
148 | "16 16 3 1",
|
---|
149 | " c None",
|
---|
150 | ". c #000000000000",
|
---|
151 | "X c #FFFFFFFFFFFF",
|
---|
152 | " ",
|
---|
153 | " ...... ",
|
---|
154 | " .XXX.X. ",
|
---|
155 | " .XXX.XX. ",
|
---|
156 | " .XXX.XXX. ",
|
---|
157 | " .XXX..... ",
|
---|
158 | " .XXXXXXX. ",
|
---|
159 | " .XXXXXXX. ",
|
---|
160 | " .XXXXXXX. ",
|
---|
161 | " .XXXXXXX. ",
|
---|
162 | " .XXXXXXX. ",
|
---|
163 | " .XXXXXXX. ",
|
---|
164 | " .XXXXXXX. ",
|
---|
165 | " ......... ",
|
---|
166 | " ",
|
---|
167 | " "};
|
---|
168 |
|
---|
169 | /* XPM */
|
---|
170 | static const char * p3_xpm[] = {
|
---|
171 | "16 16 3 1",
|
---|
172 | " c None",
|
---|
173 | ". c #000000000000",
|
---|
174 | "X c #FFFFFFFFFFFF",
|
---|
175 | " ",
|
---|
176 | " ",
|
---|
177 | " ......... ",
|
---|
178 | " ........... ",
|
---|
179 | " ........ .. ",
|
---|
180 | " ........... ",
|
---|
181 | " ........... ",
|
---|
182 | " ........... ",
|
---|
183 | " ........... ",
|
---|
184 | " ...XXXXX... ",
|
---|
185 | " ...XXXXX... ",
|
---|
186 | " ...XXXXX... ",
|
---|
187 | " ...XXXXX... ",
|
---|
188 | " ......... ",
|
---|
189 | " ",
|
---|
190 | " "};
|
---|
191 |
|
---|
192 |
|
---|
193 | /*
|
---|
194 | Auxiliary class to provide fancy menu items with different
|
---|
195 | fonts. Used for the "bold" and "underline" menu items in the options
|
---|
196 | menu.
|
---|
197 | */
|
---|
198 | class MyMenuItem : public <a href="qcustommenuitem.html">QCustomMenuItem</a>
|
---|
199 | {
|
---|
200 | public:
|
---|
201 | MyMenuItem( const <a href="qstring.html">QString</a>& s, const <a href="qfont.html">QFont</a>& f )
|
---|
202 | : string( s ), font( f ){};
|
---|
203 | ~MyMenuItem(){}
|
---|
204 |
|
---|
205 | void paint( <a href="qpainter.html">QPainter</a>* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h )
|
---|
206 | {
|
---|
207 | p-><a href="qpainter.html#setFont">setFont</a> ( font );
|
---|
208 | p-><a href="qpainter.html#drawText">drawText</a>( x, y, w, h, AlignLeft | AlignVCenter | DontClip | ShowPrefix, string );
|
---|
209 | }
|
---|
210 |
|
---|
211 | <a href="qsize.html">QSize</a> sizeHint()
|
---|
212 | {
|
---|
213 | return QFontMetrics( font ).size( AlignLeft | AlignVCenter | ShowPrefix | DontClip, string );
|
---|
214 | }
|
---|
215 | private:
|
---|
216 | <a href="qstring.html">QString</a> string;
|
---|
217 | <a href="qfont.html">QFont</a> font;
|
---|
218 | };
|
---|
219 |
|
---|
220 |
|
---|
221 | <a name="f501"></a>MenuExample::MenuExample( <a href="qwidget.html">QWidget</a> *parent, const char *name )
|
---|
222 | : <a href="qwidget.html">QWidget</a>( parent, name )
|
---|
223 | {
|
---|
224 | <a href="qpixmap.html">QPixmap</a> p1( p1_xpm );
|
---|
225 | <a href="qpixmap.html">QPixmap</a> p2( p2_xpm );
|
---|
226 | <a href="qpixmap.html">QPixmap</a> p3( p3_xpm );
|
---|
227 | <a href="qpopupmenu.html">QPopupMenu</a> *print = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
228 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( print );
|
---|
229 | <a name="x1879"></a> print-><a href="qpopupmenu.html#insertTearOffHandle">insertTearOffHandle</a>();
|
---|
230 | <a name="x1869"></a> print-><a href="qmenudata.html#insertItem">insertItem</a>( "&Print to printer", this, SLOT(printer()) );
|
---|
231 | print-><a href="qmenudata.html#insertItem">insertItem</a>( "Print to &file", this, SLOT(file()) );
|
---|
232 | print-><a href="qmenudata.html#insertItem">insertItem</a>( "Print to fa&x", this, SLOT(fax()) );
|
---|
233 | <a name="x1870"></a> print-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
234 | print-><a href="qmenudata.html#insertItem">insertItem</a>( "Printer &Setup", this, SLOT(printerSetup()) );
|
---|
235 |
|
---|
236 | <a href="qpopupmenu.html">QPopupMenu</a> *file = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
237 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( file );
|
---|
238 | file-><a href="qmenudata.html#insertItem">insertItem</a>( p1, "&Open", this, SLOT(open()), CTRL+Key_O );
|
---|
239 | file-><a href="qmenudata.html#insertItem">insertItem</a>( p2, "&New", this, SLOT(news()), CTRL+Key_N );
|
---|
240 | file-><a href="qmenudata.html#insertItem">insertItem</a>( p3, "&Save", this, SLOT(save()), CTRL+Key_S );
|
---|
241 | file-><a href="qmenudata.html#insertItem">insertItem</a>( "&Close", this, SLOT(closeDoc()), CTRL+Key_W );
|
---|
242 | file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
243 | file-><a href="qmenudata.html#insertItem">insertItem</a>( "&Print", print, CTRL+Key_P );
|
---|
244 | file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
245 | file-><a href="qmenudata.html#insertItem">insertItem</a>( "E&xit", qApp, SLOT(<a href="qapplication.html#quit">quit</a>()), CTRL+Key_Q );
|
---|
246 |
|
---|
247 | <a href="qpopupmenu.html">QPopupMenu</a> *edit = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
248 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( edit );
|
---|
249 | int undoID = edit-><a href="qmenudata.html#insertItem">insertItem</a>( "&Undo", this, SLOT(undo()) );
|
---|
250 | int redoID = edit-><a href="qmenudata.html#insertItem">insertItem</a>( "&Redo", this, SLOT(redo()) );
|
---|
251 | <a name="x1873"></a> edit-><a href="qmenudata.html#setItemEnabled">setItemEnabled</a>( undoID, FALSE );
|
---|
252 | edit-><a href="qmenudata.html#setItemEnabled">setItemEnabled</a>( redoID, FALSE );
|
---|
253 |
|
---|
254 | <a href="qpopupmenu.html">QPopupMenu</a>* options = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
255 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( options );
|
---|
256 | options-><a href="qpopupmenu.html#insertTearOffHandle">insertTearOffHandle</a>();
|
---|
257 | options-><a href="qwidget.html#setCaption">setCaption</a>("Options");
|
---|
258 | options-><a href="qmenudata.html#insertItem">insertItem</a>( "&Normal Font", this, SLOT(normal()) );
|
---|
259 | options-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
260 |
|
---|
261 | <a name="x1883"></a> options-><a href="qwidget.html#polish">polish</a>(); // adjust system settings
|
---|
262 | <a name="x1882"></a> <a href="qfont.html">QFont</a> f = options-><a href="qwidget.html#font">font</a>();
|
---|
263 | <a name="x1860"></a> f.<a href="qfont.html#setBold">setBold</a>( TRUE );
|
---|
264 | boldID = options-><a href="qmenudata.html#insertItem">insertItem</a>( new MyMenuItem( "Bold", f ) );
|
---|
265 | <a name="x1871"></a> options-><a href="qmenudata.html#setAccel">setAccel</a>( CTRL+Key_B, boldID );
|
---|
266 | <a name="x1868"></a> options-><a href="qmenudata.html#connectItem">connectItem</a>( boldID, this, SLOT(bold()) );
|
---|
267 | f = <a href="qwidget.html#font">font</a>();
|
---|
268 | <a name="x1861"></a> f.<a href="qfont.html#setUnderline">setUnderline</a>( TRUE );
|
---|
269 | underlineID = options-><a href="qmenudata.html#insertItem">insertItem</a>( new MyMenuItem( "Underline", f ) );
|
---|
270 | options-><a href="qmenudata.html#setAccel">setAccel</a>( CTRL+Key_U, underlineID );
|
---|
271 | options-><a href="qmenudata.html#connectItem">connectItem</a>( underlineID, this, SLOT(underline()) );
|
---|
272 |
|
---|
273 | isBold = FALSE;
|
---|
274 | isUnderline = FALSE;
|
---|
275 | <a name="x1880"></a> options-><a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
|
---|
276 |
|
---|
277 |
|
---|
278 | <a href="qpopupmenu.html">QPopupMenu</a> *help = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
279 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( help );
|
---|
280 | help-><a href="qmenudata.html#insertItem">insertItem</a>( "&About", this, SLOT(about()), CTRL+Key_H );
|
---|
281 | help-><a href="qmenudata.html#insertItem">insertItem</a>( "About &Qt", this, SLOT(aboutQt()) );
|
---|
282 |
|
---|
283 | // If we used a QMainWindow we could use its built-in menuBar().
|
---|
284 | menu = new <a href="qmenubar.html">QMenuBar</a>( this );
|
---|
285 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( menu );
|
---|
286 | menu-><a href="qmenudata.html#insertItem">insertItem</a>( "&File", file );
|
---|
287 | menu-><a href="qmenudata.html#insertItem">insertItem</a>( "&Edit", edit );
|
---|
288 | menu-><a href="qmenudata.html#insertItem">insertItem</a>( "&Options", options );
|
---|
289 | menu-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
290 | menu-><a href="qmenudata.html#insertItem">insertItem</a>( "&Help", help );
|
---|
291 | <a name="x1867"></a> menu-><a href="qmenubar.html#setSeparator">setSeparator</a>( QMenuBar::InWindowsStyle );
|
---|
292 |
|
---|
293 |
|
---|
294 | <a href="qlabel.html">QLabel</a> *msg = new <a href="qlabel.html">QLabel</a>( this );
|
---|
295 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( msg );
|
---|
296 | msg-><a href="qlabel.html#setText">setText</a>( "A context menu is available.\n"
|
---|
297 | "Invoke it by right-clicking or by"
|
---|
298 | " pressing the 'context' button." );
|
---|
299 | <a name="x1886"></a> msg-><a href="qwidget.html#setGeometry">setGeometry</a>( 0, height() - 60, width(), 60 );
|
---|
300 | <a name="x1864"></a> msg-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );
|
---|
301 |
|
---|
302 | label = new <a href="qlabel.html">QLabel</a>( this );
|
---|
303 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( label );
|
---|
304 | label-><a href="qwidget.html#setGeometry">setGeometry</a>( 20, rect().center().y()-20, width()-40, 40 );
|
---|
305 | label-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Raised );
|
---|
306 | <a name="x1863"></a> label-><a href="qframe.html#setLineWidth">setLineWidth</a>( 1 );
|
---|
307 | label-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );
|
---|
308 |
|
---|
309 | <a href="qobject.html#connect">connect</a>( this, SIGNAL(explain(const <a href="qstring.html">QString</a>&)),
|
---|
310 | label, SLOT(<a href="qlabel.html#setText">setText</a>(const <a href="qstring.html">QString</a>&)) );
|
---|
311 |
|
---|
312 | <a href="qwidget.html#setMinimumSize">setMinimumSize</a>( 100, 80 );
|
---|
313 | <a href="qwidget.html#setFocusPolicy">setFocusPolicy</a>( QWidget::ClickFocus );
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 | <a name="x1881"></a>void MenuExample::<a href="qwidget.html#contextMenuEvent">contextMenuEvent</a>( <a href="qcontextmenuevent.html">QContextMenuEvent</a> * )
|
---|
318 | {
|
---|
319 | <a href="qpopupmenu.html">QPopupMenu</a>* contextMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
320 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( contextMenu );
|
---|
321 | <a href="qlabel.html">QLabel</a> *caption = new <a href="qlabel.html">QLabel</a>( "<font color=darkblue><u><b>"
|
---|
322 | "Context Menu</b></u></font>", this );
|
---|
323 | caption-><a href="qlabel.html#setAlignment">setAlignment</a>( Qt::AlignCenter );
|
---|
324 | contextMenu-><a href="qmenudata.html#insertItem">insertItem</a>( caption );
|
---|
325 | contextMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "&New", this, SLOT(news()), CTRL+Key_N );
|
---|
326 | contextMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "&Open...", this, SLOT(open()), CTRL+Key_O );
|
---|
327 | contextMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "&Save", this, SLOT(save()), CTRL+Key_S );
|
---|
328 | <a href="qpopupmenu.html">QPopupMenu</a> *submenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
---|
329 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( submenu );
|
---|
330 | submenu-><a href="qmenudata.html#insertItem">insertItem</a>( "&Print to printer", this, SLOT(printer()) );
|
---|
331 | submenu-><a href="qmenudata.html#insertItem">insertItem</a>( "Print to &file", this, SLOT(file()) );
|
---|
332 | submenu-><a href="qmenudata.html#insertItem">insertItem</a>( "Print to fa&x", this, SLOT(fax()) );
|
---|
333 | contextMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "&Print", submenu );
|
---|
334 | <a name="x1878"></a><a name="x1859"></a> contextMenu-><a href="qpopupmenu.html#exec">exec</a>( QCursor::<a href="qcursor.html#pos">pos</a>() );
|
---|
335 | delete contextMenu;
|
---|
336 | }
|
---|
337 |
|
---|
338 |
|
---|
339 | void <a name="f502"></a>MenuExample::open()
|
---|
340 | {
|
---|
341 | emit explain( "File/Open selected" );
|
---|
342 | }
|
---|
343 |
|
---|
344 |
|
---|
345 | void <a name="f503"></a>MenuExample::news()
|
---|
346 | {
|
---|
347 | emit explain( "File/New selected" );
|
---|
348 | }
|
---|
349 |
|
---|
350 | void <a name="f504"></a>MenuExample::save()
|
---|
351 | {
|
---|
352 | emit explain( "File/Save selected" );
|
---|
353 | }
|
---|
354 |
|
---|
355 |
|
---|
356 | void <a name="f505"></a>MenuExample::closeDoc()
|
---|
357 | {
|
---|
358 | emit explain( "File/Close selected" );
|
---|
359 | }
|
---|
360 |
|
---|
361 |
|
---|
362 | void <a name="f506"></a>MenuExample::undo()
|
---|
363 | {
|
---|
364 | emit explain( "Edit/Undo selected" );
|
---|
365 | }
|
---|
366 |
|
---|
367 |
|
---|
368 | void <a name="f507"></a>MenuExample::redo()
|
---|
369 | {
|
---|
370 | emit explain( "Edit/Redo selected" );
|
---|
371 | }
|
---|
372 |
|
---|
373 |
|
---|
374 | void <a name="f508"></a>MenuExample::normal()
|
---|
375 | {
|
---|
376 | isBold = FALSE;
|
---|
377 | isUnderline = FALSE;
|
---|
378 | <a href="qfont.html">QFont</a> font;
|
---|
379 | <a name="x1865"></a> label-><a href="qlabel.html#setFont">setFont</a>( font );
|
---|
380 | <a name="x1872"></a> menu-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( boldID, isBold );
|
---|
381 | menu-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( underlineID, isUnderline );
|
---|
382 | emit explain( "Options/Normal selected" );
|
---|
383 | }
|
---|
384 |
|
---|
385 |
|
---|
386 | void <a name="f509"></a>MenuExample::bold()
|
---|
387 | {
|
---|
388 | isBold = !isBold;
|
---|
389 | <a href="qfont.html">QFont</a> font;
|
---|
390 | font.<a href="qfont.html#setBold">setBold</a>( isBold );
|
---|
391 | font.<a href="qfont.html#setUnderline">setUnderline</a>( isUnderline );
|
---|
392 | label-><a href="qlabel.html#setFont">setFont</a>( font );
|
---|
393 | menu-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( boldID, isBold );
|
---|
394 | emit explain( "Options/Bold selected" );
|
---|
395 | }
|
---|
396 |
|
---|
397 |
|
---|
398 | void <a name="f510"></a>MenuExample::underline()
|
---|
399 | {
|
---|
400 | isUnderline = !isUnderline;
|
---|
401 | <a href="qfont.html">QFont</a> font;
|
---|
402 | font.<a href="qfont.html#setBold">setBold</a>( isBold );
|
---|
403 | font.<a href="qfont.html#setUnderline">setUnderline</a>( isUnderline );
|
---|
404 | label-><a href="qlabel.html#setFont">setFont</a>( font );
|
---|
405 | menu-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( underlineID, isUnderline );
|
---|
406 | emit explain( "Options/Underline selected" );
|
---|
407 | }
|
---|
408 |
|
---|
409 |
|
---|
410 | void <a name="f511"></a>MenuExample::about()
|
---|
411 | {
|
---|
412 | <a name="x1874"></a> QMessageBox::<a href="qmessagebox.html#about">about</a>( this, "Qt Menu Example",
|
---|
413 | "This example demonstrates simple use of Qt menus.\n"
|
---|
414 | "You can cut and paste lines from it to your own\n"
|
---|
415 | "programs." );
|
---|
416 | }
|
---|
417 |
|
---|
418 |
|
---|
419 | void <a name="f512"></a>MenuExample::aboutQt()
|
---|
420 | {
|
---|
421 | <a name="x1875"></a> QMessageBox::<a href="qmessagebox.html#aboutQt">aboutQt</a>( this, "Qt Menu Example" );
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 | void <a name="f513"></a>MenuExample::printer()
|
---|
426 | {
|
---|
427 | emit explain( "File/Printer/Print selected" );
|
---|
428 | }
|
---|
429 |
|
---|
430 | void <a name="f514"></a>MenuExample::file()
|
---|
431 | {
|
---|
432 | emit explain( "File/Printer/Print To File selected" );
|
---|
433 | }
|
---|
434 |
|
---|
435 | void <a name="f515"></a>MenuExample::fax()
|
---|
436 | {
|
---|
437 | emit explain( "File/Printer/Print To Fax selected" );
|
---|
438 | }
|
---|
439 |
|
---|
440 | void <a name="f516"></a>MenuExample::printerSetup()
|
---|
441 | {
|
---|
442 | emit explain( "File/Printer/Printer Setup selected" );
|
---|
443 | }
|
---|
444 |
|
---|
445 |
|
---|
446 | <a name="x1884"></a>void MenuExample::<a href="qwidget.html#resizeEvent">resizeEvent</a>( <a href="qresizeevent.html">QResizeEvent</a> * )
|
---|
447 | {
|
---|
448 | label-><a href="qwidget.html#setGeometry">setGeometry</a>( 20, rect().center().y()-20, width()-40, 40 );
|
---|
449 | }
|
---|
450 |
|
---|
451 |
|
---|
452 | int main( int argc, char ** argv )
|
---|
453 | {
|
---|
454 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
455 | MenuExample m;
|
---|
456 | m.<a href="qwidget.html#setCaption">setCaption</a>("Qt Examples - Menus");
|
---|
457 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &m );
|
---|
458 | m.<a href="qwidget.html#show">show</a>();
|
---|
459 | return a.<a href="qapplication.html#exec">exec</a>();
|
---|
460 | }
|
---|
461 | </pre>
|
---|
462 |
|
---|
463 | <p>See also <a href="examples.html">Examples</a>.
|
---|
464 |
|
---|
465 | <!-- eof -->
|
---|
466 | <p><address><hr><div align=center>
|
---|
467 | <table width=100% cellspacing=0 border=0><tr>
|
---|
468 | <td>Copyright © 2007
|
---|
469 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
470 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
471 | </table></div></address></body>
|
---|
472 | </html>
|
---|