|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/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"><!--
|
|
|
|
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 a menu bar with pull-down menus,
|
|
|
|
sub-menus and custom menu items. It also demonstrates a pop-up
|
|
|
|
context menu.
|
|
|
|
<p> <hr>
|
|
|
|
<p> Header file:
|
|
|
|
<p> <pre>/****************************************************************************
|
|
|
|
** $Id: qt/menu.h 3.3.8 edited Jan 11 14:37 $
|
|
|
|
**
|
|
|
|
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|
|
|
**
|
|
|
|
** This file is part of an example program for TQt. This example
|
|
|
|
** program may be used, distributed and modified without limitation.
|
|
|
|
**
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef MENU_H
|
|
|
|
#define MENU_H
|
|
|
|
|
|
|
|
#include <<a href="tqwidget-h.html">tqwidget.h</a>>
|
|
|
|
#include <<a href="tqmenubar-h.html">tqmenubar.h</a>>
|
|
|
|
#include <<a href="tqlabel-h.html">tqlabel.h</a>>
|
|
|
|
|
|
|
|
|
|
|
|
class MenuExample : public <a href="tqwidget.html">TQWidget</a>
|
|
|
|
{
|
|
|
|
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
|
|
|
|
public:
|
|
|
|
MenuExample( <a href="tqwidget.html">TQWidget</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 aboutTQt();
|
|
|
|
void printer();
|
|
|
|
void file();
|
|
|
|
void fax();
|
|
|
|
void printerSetup();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent( <a href="qresizeevent.html">TQResizeEvent</a> * );
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void explain( const <a href="tqstring.html">TQString</a>& );
|
|
|
|
|
|
|
|
private:
|
|
|
|
void contextMenuEvent ( <a href="qcontextmenuevent.html">TQContextMenuEvent</a> * );
|
|
|
|
|
|
|
|
|
|
|
|
<a href="tqmenubar.html">TQMenuBar</a> *menu;
|
|
|
|
<a href="tqlabel.html">TQLabel</a> *label;
|
|
|
|
bool isBold;
|
|
|
|
bool isUnderline;
|
|
|
|
int boldID, underlineID;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // MENU_H
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p> <hr>
|
|
|
|
<p> Implementation:
|
|
|
|
<p> <pre>/****************************************************************************
|
|
|
|
** $Id: qt/menu.cpp 3.3.8 edited Jan 11 14:37 $
|
|
|
|
**
|
|
|
|
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|
|
|
**
|
|
|
|
** This file is part of an example program for TQt. This example
|
|
|
|
** program may be used, distributed and modified without limitation.
|
|
|
|
**
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "menu.h"
|
|
|
|
#include <<a href="qcursor-h.html">ntqcursor.h</a>>
|
|
|
|
#include <<a href="tqpopupmenu-h.html">tqpopupmenu.h</a>>
|
|
|
|
#include <<a href="qapplication-h.html">ntqapplication.h</a>>
|
|
|
|
#include <<a href="qmessagebox-h.html">ntqmessagebox.h</a>>
|
|
|
|
#include <<a href="tqpixmap-h.html">tqpixmap.h</a>>
|
|
|
|
#include <<a href="tqpainter-h.html">tqpainter.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">TQCustomMenuItem</a>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyMenuItem( const <a href="tqstring.html">TQString</a>& s, const <a href="tqfont.html">TQFont</a>& f )
|
|
|
|
: string( s ), font( f ){};
|
|
|
|
~MyMenuItem(){}
|
|
|
|
|
|
|
|
void paint( <a href="tqpainter.html">TQPainter</a>* p, const TQColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h )
|
|
|
|
{
|
|
|
|
p-><a href="tqpainter.html#setFont">setFont</a> ( font );
|
|
|
|
p-><a href="tqpainter.html#drawText">drawText</a>( x, y, w, h, AlignLeft | AlignVCenter | DontClip | ShowPrefix, string );
|
|
|
|
}
|
|
|
|
|
|
|
|
<a href="tqsize.html">TQSize</a> sizeHint()
|
|
|
|
{
|
|
|
|
return TQFontMetrics( font ).size( AlignLeft | AlignVCenter | ShowPrefix | DontClip, string );
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
<a href="tqstring.html">TQString</a> string;
|
|
|
|
<a href="tqfont.html">TQFont</a> font;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
<a name="f501"></a>MenuExample::MenuExample( <a href="tqwidget.html">TQWidget</a> *parent, const char *name )
|
|
|
|
: <a href="tqwidget.html">TQWidget</a>( parent, name )
|
|
|
|
{
|
|
|
|
<a href="tqpixmap.html">TQPixmap</a> p1( p1_xpm );
|
|
|
|
<a href="tqpixmap.html">TQPixmap</a> p2( p2_xpm );
|
|
|
|
<a href="tqpixmap.html">TQPixmap</a> p3( p3_xpm );
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a> *print = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( print );
|
|
|
|
<a name="x1879"></a> print-><a href="tqpopupmenu.html#insertTearOffHandle">insertTearOffHandle</a>();
|
|
|
|
<a name="x1869"></a> print-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Print to printer", this, TQ_SLOT(printer()) );
|
|
|
|
print-><a href="tqmenudata.html#insertItem">insertItem</a>( "Print to &file", this, TQ_SLOT(file()) );
|
|
|
|
print-><a href="tqmenudata.html#insertItem">insertItem</a>( "Print to fa&x", this, TQ_SLOT(fax()) );
|
|
|
|
<a name="x1870"></a> print-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
print-><a href="tqmenudata.html#insertItem">insertItem</a>( "Printer &Setup", this, TQ_SLOT(printerSetup()) );
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a> *file = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( file );
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( p1, "&Open", this, TQ_SLOT(open()), CTRL+Key_O );
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( p2, "&New", this, TQ_SLOT(news()), CTRL+Key_N );
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( p3, "&Save", this, TQ_SLOT(save()), CTRL+Key_S );
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Close", this, TQ_SLOT(closeDoc()), CTRL+Key_W );
|
|
|
|
file-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Print", print, CTRL+Key_P );
|
|
|
|
file-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>( "E&xit", tqApp, TQ_SLOT(<a href="ntqapplication.html#quit">quit</a>()), CTRL+Key_Q );
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a> *edit = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( edit );
|
|
|
|
int undoID = edit-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Undo", this, TQ_SLOT(undo()) );
|
|
|
|
int redoID = edit-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Redo", this, TQ_SLOT(redo()) );
|
|
|
|
<a name="x1873"></a> edit-><a href="tqmenudata.html#setItemEnabled">setItemEnabled</a>( undoID, FALSE );
|
|
|
|
edit-><a href="tqmenudata.html#setItemEnabled">setItemEnabled</a>( redoID, FALSE );
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a>* options = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( options );
|
|
|
|
options-><a href="tqpopupmenu.html#insertTearOffHandle">insertTearOffHandle</a>();
|
|
|
|
options-><a href="tqwidget.html#setCaption">setCaption</a>("Options");
|
|
|
|
options-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Normal Font", this, TQ_SLOT(normal()) );
|
|
|
|
options-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
|
|
|
|
<a name="x1883"></a> options-><a href="tqwidget.html#polish">polish</a>(); // adjust system settings
|
|
|
|
<a name="x1882"></a> <a href="tqfont.html">TQFont</a> f = options-><a href="tqwidget.html#font">font</a>();
|
|
|
|
<a name="x1860"></a> f.<a href="tqfont.html#setBold">setBold</a>( TRUE );
|
|
|
|
boldID = options-><a href="tqmenudata.html#insertItem">insertItem</a>( new MyMenuItem( "Bold", f ) );
|
|
|
|
<a name="x1871"></a> options-><a href="tqmenudata.html#setAccel">setAccel</a>( CTRL+Key_B, boldID );
|
|
|
|
<a name="x1868"></a> options-><a href="tqmenudata.html#connectItem">connectItem</a>( boldID, this, TQ_SLOT(bold()) );
|
|
|
|
f = <a href="tqwidget.html#font">font</a>();
|
|
|
|
<a name="x1861"></a> f.<a href="tqfont.html#setUnderline">setUnderline</a>( TRUE );
|
|
|
|
underlineID = options-><a href="tqmenudata.html#insertItem">insertItem</a>( new MyMenuItem( "Underline", f ) );
|
|
|
|
options-><a href="tqmenudata.html#setAccel">setAccel</a>( CTRL+Key_U, underlineID );
|
|
|
|
options-><a href="tqmenudata.html#connectItem">connectItem</a>( underlineID, this, TQ_SLOT(underline()) );
|
|
|
|
|
|
|
|
isBold = FALSE;
|
|
|
|
isUnderline = FALSE;
|
|
|
|
<a name="x1880"></a> options-><a href="tqpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
|
|
|
|
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a> *help = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( help );
|
|
|
|
help-><a href="tqmenudata.html#insertItem">insertItem</a>( "&About", this, TQ_SLOT(about()), CTRL+Key_H );
|
|
|
|
help-><a href="tqmenudata.html#insertItem">insertItem</a>( "About &TQt", this, TQ_SLOT(aboutTQt()) );
|
|
|
|
|
|
|
|
// If we used a TQMainWindow we could use its built-in menuBar().
|
|
|
|
menu = new <a href="tqmenubar.html">TQMenuBar</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( menu );
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&File", file );
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Edit", edit );
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Options", options );
|
|
|
|
menu-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Help", help );
|
|
|
|
<a name="x1867"></a> menu-><a href="tqmenubar.html#setSeparator">setSeparator</a>( TQMenuBar::InWindowsStyle );
|
|
|
|
|
|
|
|
|
|
|
|
<a href="tqlabel.html">TQLabel</a> *msg = new <a href="tqlabel.html">TQLabel</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( msg );
|
|
|
|
msg-><a href="tqlabel.html#setText">setText</a>( "A context menu is available.\n"
|
|
|
|
"Invoke it by right-clicking or by"
|
|
|
|
" pressing the 'context' button." );
|
|
|
|
<a name="x1886"></a> msg-><a href="tqwidget.html#setGeometry">setGeometry</a>( 0, height() - 60, width(), 60 );
|
|
|
|
<a name="x1864"></a> msg-><a href="tqlabel.html#setAlignment">setAlignment</a>( AlignCenter );
|
|
|
|
|
|
|
|
label = new <a href="tqlabel.html">TQLabel</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( label );
|
|
|
|
label-><a href="tqwidget.html#setGeometry">setGeometry</a>( 20, rect().center().y()-20, width()-40, 40 );
|
|
|
|
label-><a href="ntqframe.html#setFrameStyle">setFrameStyle</a>( TQFrame::Box | TQFrame::Raised );
|
|
|
|
<a name="x1863"></a> label-><a href="ntqframe.html#setLineWidth">setLineWidth</a>( 1 );
|
|
|
|
label-><a href="tqlabel.html#setAlignment">setAlignment</a>( AlignCenter );
|
|
|
|
|
|
|
|
<a href="tqobject.html#connect">connect</a>( this, TQ_SIGNAL(explain(const <a href="tqstring.html">TQString</a>&)),
|
|
|
|
label, TQ_SLOT(<a href="tqlabel.html#setText">setText</a>(const <a href="tqstring.html">TQString</a>&)) );
|
|
|
|
|
|
|
|
<a href="tqwidget.html#setMinimumSize">setMinimumSize</a>( 100, 80 );
|
|
|
|
<a href="tqwidget.html#setFocusPolicy">setFocusPolicy</a>( TQWidget::ClickFocus );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
<a name="x1881"></a>void MenuExample::<a href="tqwidget.html#contextMenuEvent">contextMenuEvent</a>( <a href="qcontextmenuevent.html">TQContextMenuEvent</a> * )
|
|
|
|
{
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a>* contextMenu = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( contextMenu );
|
|
|
|
<a href="tqlabel.html">TQLabel</a> *caption = new <a href="tqlabel.html">TQLabel</a>( "<font color=darkblue><u><b>"
|
|
|
|
"Context Menu</b></u></font>", this );
|
|
|
|
caption-><a href="tqlabel.html#setAlignment">setAlignment</a>( TQt::AlignCenter );
|
|
|
|
contextMenu-><a href="tqmenudata.html#insertItem">insertItem</a>( caption );
|
|
|
|
contextMenu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&New", this, TQ_SLOT(news()), CTRL+Key_N );
|
|
|
|
contextMenu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Open...", this, TQ_SLOT(open()), CTRL+Key_O );
|
|
|
|
contextMenu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Save", this, TQ_SLOT(save()), CTRL+Key_S );
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a> *submenu = new <a href="tqpopupmenu.html">TQPopupMenu</a>( this );
|
|
|
|
<a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( submenu );
|
|
|
|
submenu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Print to printer", this, TQ_SLOT(printer()) );
|
|
|
|
submenu-><a href="tqmenudata.html#insertItem">insertItem</a>( "Print to &file", this, TQ_SLOT(file()) );
|
|
|
|
submenu-><a href="tqmenudata.html#insertItem">insertItem</a>( "Print to fa&x", this, TQ_SLOT(fax()) );
|
|
|
|
contextMenu-><a href="tqmenudata.html#insertItem">insertItem</a>( "&Print", submenu );
|
|
|
|
<a name="x1878"></a><a name="x1859"></a> contextMenu-><a href="tqpopupmenu.html#exec">exec</a>( TQCursor::<a href="ntqcursor.html#pos">pos</a>() );
|
|
|
|
delete contextMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f502"></a>MenuExample::open()
|
|
|
|
{
|
|
|
|
emit explain( "File/Open selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f503"></a>MenuExample::news()
|
|
|
|
{
|
|
|
|
emit explain( "File/New selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f504"></a>MenuExample::save()
|
|
|
|
{
|
|
|
|
emit explain( "File/Save selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f505"></a>MenuExample::closeDoc()
|
|
|
|
{
|
|
|
|
emit explain( "File/Close selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f506"></a>MenuExample::undo()
|
|
|
|
{
|
|
|
|
emit explain( "Edit/Undo selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f507"></a>MenuExample::redo()
|
|
|
|
{
|
|
|
|
emit explain( "Edit/Redo selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f508"></a>MenuExample::normal()
|
|
|
|
{
|
|
|
|
isBold = FALSE;
|
|
|
|
isUnderline = FALSE;
|
|
|
|
<a href="tqfont.html">TQFont</a> font;
|
|
|
|
<a name="x1865"></a> label-><a href="tqlabel.html#setFont">setFont</a>( font );
|
|
|
|
<a name="x1872"></a> menu-><a href="tqmenudata.html#setItemChecked">setItemChecked</a>( boldID, isBold );
|
|
|
|
menu-><a href="tqmenudata.html#setItemChecked">setItemChecked</a>( underlineID, isUnderline );
|
|
|
|
emit explain( "Options/Normal selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f509"></a>MenuExample::bold()
|
|
|
|
{
|
|
|
|
isBold = !isBold;
|
|
|
|
<a href="tqfont.html">TQFont</a> font;
|
|
|
|
font.<a href="tqfont.html#setBold">setBold</a>( isBold );
|
|
|
|
font.<a href="tqfont.html#setUnderline">setUnderline</a>( isUnderline );
|
|
|
|
label-><a href="tqlabel.html#setFont">setFont</a>( font );
|
|
|
|
menu-><a href="tqmenudata.html#setItemChecked">setItemChecked</a>( boldID, isBold );
|
|
|
|
emit explain( "Options/Bold selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f510"></a>MenuExample::underline()
|
|
|
|
{
|
|
|
|
isUnderline = !isUnderline;
|
|
|
|
<a href="tqfont.html">TQFont</a> font;
|
|
|
|
font.<a href="tqfont.html#setBold">setBold</a>( isBold );
|
|
|
|
font.<a href="tqfont.html#setUnderline">setUnderline</a>( isUnderline );
|
|
|
|
label-><a href="tqlabel.html#setFont">setFont</a>( font );
|
|
|
|
menu-><a href="tqmenudata.html#setItemChecked">setItemChecked</a>( underlineID, isUnderline );
|
|
|
|
emit explain( "Options/Underline selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f511"></a>MenuExample::about()
|
|
|
|
{
|
|
|
|
<a name="x1874"></a> TQMessageBox::<a href="ntqmessagebox.html#about">about</a>( this, "TQt Menu Example",
|
|
|
|
"This example demonstrates simple use of TQt menus.\n"
|
|
|
|
"You can cut and paste lines from it to your own\n"
|
|
|
|
"programs." );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f512"></a>MenuExample::aboutTQt()
|
|
|
|
{
|
|
|
|
<a name="x1875"></a> TQMessageBox::<a href="ntqmessagebox.html#aboutTQt">aboutTQt</a>( this, "TQt Menu Example" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f513"></a>MenuExample::printer()
|
|
|
|
{
|
|
|
|
emit explain( "File/Printer/Print selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f514"></a>MenuExample::file()
|
|
|
|
{
|
|
|
|
emit explain( "File/Printer/Print To File selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f515"></a>MenuExample::fax()
|
|
|
|
{
|
|
|
|
emit explain( "File/Printer/Print To Fax selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f516"></a>MenuExample::printerSetup()
|
|
|
|
{
|
|
|
|
emit explain( "File/Printer/Printer Setup selected" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
<a name="x1884"></a>void MenuExample::<a href="tqwidget.html#resizeEvent">resizeEvent</a>( <a href="qresizeevent.html">TQResizeEvent</a> * )
|
|
|
|
{
|
|
|
|
label-><a href="tqwidget.html#setGeometry">setGeometry</a>( 20, rect().center().y()-20, width()-40, 40 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main( int argc, char ** argv )
|
|
|
|
{
|
|
|
|
<a href="ntqapplication.html">TQApplication</a> a( argc, argv );
|
|
|
|
MenuExample m;
|
|
|
|
m.<a href="tqwidget.html#setCaption">setCaption</a>("TQt Examples - Menus");
|
|
|
|
a.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &m );
|
|
|
|
m.<a href="tqwidget.html#show">show</a>();
|
|
|
|
return a.<a href="ntqapplication.html#exec">exec</a>();
|
|
|
|
}
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>See also <a href="examples.html">Examples</a>.
|
|
|
|
|
|
|
|
<!-- eof -->
|
|
|
|
<p><address><hr><div align=center>
|
|
|
|
<table width=100% cellspacing=0 border=0><tr>
|
|
|
|
<td>Copyright © 2007
|
|
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
|
|
</table></div></address></body>
|
|
|
|
</html>
|