<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/examples/action/actiongroup/actiongroup.doc:4 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>A Tiny Example Featuring QActionGroup</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>A Tiny Example Featuring QActionGroup</h1> <p> <p> This example program shows how to use an exclusive action group. <p> Detailed explanations of the code can be found in the <a href="actiongroup.html">walkthrough</a>. <p> <hr> <p> Main: <p> <pre>/* $Id$ */ #include <<a href="qapplication-h.html">qapplication.h</a>> #include "editor.h" int main( int argc, char ** argv) { <a href="qapplication.html">QApplication</a> app( argc, argv ); Editor editor; editor.<a href="qwidget.html#setCaption">setCaption</a>( "Qt Example - Actiongroup" ); app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &editor ); editor.<a href="qwidget.html#show">show</a>(); return app.<a href="qapplication.html#exec">exec</a>(); } </pre> <p> <hr> <p> Header file: <p> <pre>/* $Id$ */ #ifndef EDITOR_H #define EDITOR_H #include <<a href="qmainwindow-h.html">qmainwindow.h</a>> class QTextEdit; class QAction; class Editor : public <a href="qmainwindow.html">QMainWindow</a> { <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a> public: Editor(); private slots: void setFontColor( <a href="qaction.html">QAction</a> * ); private: <a href="qtextedit.html">QTextEdit</a> * editor; <a href="qaction.html">QAction</a> * setRedFont; }; #endif </pre> <p> <hr> <p> Implementation: <p> <pre>/* $Id$ */ /* XPM */ static const char * black_xpm[] = { "32 32 2 1", " c None", ". c #020202", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................", "................................"}; /* XPM */ static const char * red_xpm[] = { "32 32 6 1", " c None", ". c #EE0928", "+ c #EF0928", "@ c #EE0A29", "# c #EE0B2A", "$ c #ED0C2B", "........................+.......", ".+.++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++.+++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "+++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++.+++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++.+++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++@", ".+++++++++++++++++++++++++++++.#", ".+++++++++++++++++++++++++.+++.$", ".+++++++++++++++++++++++++++++#$", ".+++++++++++++++++++++++++++++.#", ".+++++++++++++++++++++++++++++.#", ".++++++++.+++++++++++++++++++++@", ".++++++.+++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "..........+.............+......."}; #include "editor.h" #include <<a href="qtextedit-h.html">qtextedit.h</a>> #include <<a href="qmenubar-h.html">qmenubar.h</a>> #include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>> #include <<a href="qtoolbar-h.html">qtoolbar.h</a>> #include <<a href="qaction-h.html">qaction.h</a>> <a name="f535"></a>Editor::Editor() : <a href="qmainwindow.html">QMainWindow</a>( 0, "main window") { <a href="qactiongroup.html">QActionGroup</a> * colors = new <a href="qactiongroup.html">QActionGroup</a>( this, "colors", TRUE ); <a href="qaction.html">QAction</a> * setBlackFont = new <a href="qaction.html">QAction</a>( "black", QPixmap( (const char**)black_xpm ), "Font color: black", CTRL+Key_B, colors, "blackfontcolor", TRUE ); setRedFont = new <a href="qaction.html">QAction</a>( "red", QPixmap( (const char**)red_xpm ), "Font color: red", CTRL+Key_R, colors, "redfontcolor", TRUE ); <a name="x2007"></a> QObject::<a href="qobject.html#connect">connect</a>( colors, SIGNAL( <a href="qactiongroup.html#selected">selected</a>( <a href="qaction.html">QAction</a> * ) ), this, SLOT( setFontColor( <a href="qaction.html">QAction</a> * ) ) ); <a href="qtoolbar.html">QToolBar</a> * toolbar = new <a href="qtoolbar.html">QToolBar</a>( this, "toolbar" ); <a name="x2006"></a> colors-><a href="qactiongroup.html#addTo">addTo</a>( toolbar ); <a href="qpopupmenu.html">QPopupMenu</a> * font = new <a href="qpopupmenu.html">QPopupMenu</a>( this ); <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Font", font ); <a name="x2008"></a> colors-><a href="qactiongroup.html#setUsesDropDown">setUsesDropDown</a>( TRUE ); <a name="x2005"></a> colors-><a href="qaction.html#setMenuText">setMenuText</a>( "Font Color" ); colors-><a href="qactiongroup.html#addTo">addTo</a>( font ); editor = new <a href="qtextedit.html">QTextEdit</a>( this, "editor" ); <a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( editor ); } void <a name="f536"></a>Editor::setFontColor( <a href="qaction.html">QAction</a> * coloraction ) { if ( coloraction == setRedFont ) <a name="x2010"></a> editor-><a href="qtextedit.html#setColor">setColor</a>( red ); else editor-><a href="qtextedit.html#setColor">setColor</a>( black ); } </pre> <p>See also <a href="qaction-examples.html">QAction Examples</a>. <!-- eof --> <p><address><hr><div align=center> <table width=100% cellspacing=0 border=0><tr> <td>Copyright © 2001 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a> <td align=right><div align=right>Qt version 3.0.2</div> </table></div></address></body> </html>