qcombobox.html

来自「QT 下载资料仅供参考」· HTML 代码 · 共 561 行 · 第 1/3 页

HTML
561
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/widgets/qcombobox.cpp:56 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QComboBox Class</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&nbsp;Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped&nbsp;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>QComboBox Class Reference</h1><p>The QComboBox widget is a combined button and popup list.<a href="#details">More...</a><p><tt>#include &lt;<a href="qcombobox-h.html">qcombobox.h</a>&gt;</tt><p>Inherits <a href="qwidget.html">QWidget</a>.<p><a href="qcombobox-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QComboBox"><b>QComboBox</b></a> ( QWidget&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</div></li><li><div class=fn><a href="#QComboBox-2"><b>QComboBox</b></a> ( bool&nbsp;rw, QWidget&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</div></li><li><div class=fn><a href="#~QComboBox"><b>~QComboBox</b></a> ()</div></li><li><div class=fn>int <a href="#count"><b>count</b></a> () const</div></li><li><div class=fn>void <a href="#insertStringList"><b>insertStringList</b></a> ( const&nbsp;QStringList&nbsp;&amp;&nbsp;list, int&nbsp;index = -1 )</div></li><li><div class=fn>void <a href="#insertStrList-2"><b>insertStrList</b></a> ( const&nbsp;QStrList&nbsp;&amp;&nbsp;list, int&nbsp;index = -1 )</div></li><li><div class=fn>void <a href="#insertStrList-3"><b>insertStrList</b></a> ( const&nbsp;QStrList&nbsp;*&nbsp;list, int&nbsp;index = -1 )</div></li><li><div class=fn>void <a href="#insertStrList"><b>insertStrList</b></a> ( const&nbsp;char&nbsp;**&nbsp;strings, int&nbsp;numStrings = -1, int&nbsp;index = -1 )</div></li><li><div class=fn>void <a href="#insertItem"><b>insertItem</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;t, int&nbsp;index = -1 )</div></li><li><div class=fn>void <a href="#insertItem-2"><b>insertItem</b></a> ( const&nbsp;QPixmap&nbsp;&amp;&nbsp;pixmap, int&nbsp;index = -1 )</div></li><li><div class=fn>void <a href="#insertItem-3"><b>insertItem</b></a> ( const&nbsp;QPixmap&nbsp;&amp;&nbsp;pixmap, const&nbsp;QString&nbsp;&amp;&nbsp;text, int&nbsp;index = -1 )</div></li><li><div class=fn>void <a href="#removeItem"><b>removeItem</b></a> ( int&nbsp;index )</div></li><li><div class=fn>int <a href="#currentItem"><b>currentItem</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setCurrentItem"><b>setCurrentItem</b></a> ( int&nbsp;index )</div></li><li><div class=fn>QString <a href="#currentText"><b>currentText</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setCurrentText"><b>setCurrentText</b></a> ( const QString &amp; )</div></li><li><div class=fn>QString <a href="#text"><b>text</b></a> ( int&nbsp;index ) const</div></li><li><div class=fn>const QPixmap * <a href="#pixmap"><b>pixmap</b></a> ( int&nbsp;index ) const</div></li><li><div class=fn>void <a href="#changeItem"><b>changeItem</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;t, int&nbsp;index )</div></li><li><div class=fn>void <a href="#changeItem-2"><b>changeItem</b></a> ( const&nbsp;QPixmap&nbsp;&amp;&nbsp;im, int&nbsp;index )</div></li><li><div class=fn>void <a href="#changeItem-3"><b>changeItem</b></a> ( const&nbsp;QPixmap&nbsp;&amp;&nbsp;im, const&nbsp;QString&nbsp;&amp;&nbsp;t, int&nbsp;index )</div></li><li><div class=fn>bool autoResize () const &nbsp;<em>(obsolete)</em></div></li><li><div class=fn>virtual void setAutoResize ( bool ) &nbsp;<em>(obsolete)</em></div></li><li><div class=fn>virtual void <a href="#setPalette"><b>setPalette</b></a> ( const&nbsp;QPalette&nbsp;&amp;&nbsp;palette )</div></li><li><div class=fn>virtual void <a href="#setFont"><b>setFont</b></a> ( const&nbsp;QFont&nbsp;&amp;&nbsp;font )</div></li><li><div class=fn>virtual void <a href="#setSizeLimit"><b>setSizeLimit</b></a> ( int )</div></li><li><div class=fn>int <a href="#sizeLimit"><b>sizeLimit</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setMaxCount"><b>setMaxCount</b></a> ( int )</div></li><li><div class=fn>int <a href="#maxCount"><b>maxCount</b></a> () const</div></li><li><div class=fn>enum <a href="#Policy-enum"><b>Policy</b></a> { NoInsertion, AtTop, AtCurrent, AtBottom, AfterCurrent, BeforeCurrent }</div></li><li><div class=fn>virtual void <a href="#setInsertionPolicy"><b>setInsertionPolicy</b></a> ( Policy&nbsp;policy )</div></li><li><div class=fn>Policy <a href="#insertionPolicy"><b>insertionPolicy</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setValidator"><b>setValidator</b></a> ( const&nbsp;QValidator&nbsp;*&nbsp;v )</div></li><li><div class=fn>const QValidator * <a href="#validator"><b>validator</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setListBox"><b>setListBox</b></a> ( QListBox&nbsp;*&nbsp;newListBox )</div></li><li><div class=fn>QListBox * <a href="#listBox"><b>listBox</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setLineEdit"><b>setLineEdit</b></a> ( QLineEdit&nbsp;*&nbsp;edit )</div></li><li><div class=fn>QLineEdit * <a href="#lineEdit"><b>lineEdit</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setAutoCompletion"><b>setAutoCompletion</b></a> ( bool )</div></li><li><div class=fn>bool <a href="#autoCompletion"><b>autoCompletion</b></a> () const</div></li><li><div class=fn>void <a href="#setDuplicatesEnabled"><b>setDuplicatesEnabled</b></a> ( bool&nbsp;enable )</div></li><li><div class=fn>bool <a href="#duplicatesEnabled"><b>duplicatesEnabled</b></a> () const</div></li><li><div class=fn>bool <a href="#editable"><b>editable</b></a> () const</div></li><li><div class=fn>void <a href="#setEditable"><b>setEditable</b></a> ( bool )</div></li><li><div class=fn>virtual void <a href="#popup"><b>popup</b></a> ()</div></li></ul><h2>Public Slots</h2><ul><li><div class=fn>void <a href="#clear"><b>clear</b></a> ()</div></li><li><div class=fn>void <a href="#clearValidator"><b>clearValidator</b></a> ()</div></li><li><div class=fn>void <a href="#clearEdit"><b>clearEdit</b></a> ()</div></li><li><div class=fn>virtual void <a href="#setEditText"><b>setEditText</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;newText )</div></li></ul><h2>Signals</h2><ul><li><div class=fn>void <a href="#activated"><b>activated</b></a> ( int&nbsp;index )</div></li><li><div class=fn>void <a href="#highlighted"><b>highlighted</b></a> ( int&nbsp;index )</div></li><li><div class=fn>void <a href="#activated-2"><b>activated</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;string )</div></li><li><div class=fn>void <a href="#highlighted-2"><b>highlighted</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;string )</div></li><li><div class=fn>void <a href="#textChanged"><b>textChanged</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;string )</div></li></ul><h2>Properties</h2><ul><li><div class=fn>bool <a href="#autoCompletion-prop"><b>autoCompletion</b></a>&nbsp;- whether auto-completion is enabled</div></li><li><div class=fn>bool <a href="#autoMask-prop"><b>autoMask</b></a>&nbsp;- whether the combobox is automatically masked &nbsp;<em>(read only)</em></div></li><li><div class=fn>bool autoResize&nbsp;- whether auto resize is enabled &nbsp;<em>(obsolete)</em></div></li><li><div class=fn>int <a href="#count-prop"><b>count</b></a>&nbsp;- the number of items in the combobox &nbsp;<em>(read only)</em></div></li><li><div class=fn>int <a href="#currentItem-prop"><b>currentItem</b></a>&nbsp;- the index of the current item in the combobox</div></li><li><div class=fn>QString <a href="#currentText-prop"><b>currentText</b></a>&nbsp;- the text of the combobox's current item</div></li><li><div class=fn>bool <a href="#duplicatesEnabled-prop"><b>duplicatesEnabled</b></a>&nbsp;- whether duplicates are allowed</div></li><li><div class=fn>bool <a href="#editable-prop"><b>editable</b></a>&nbsp;- whether the combobox is editable</div></li><li><div class=fn>Policy <a href="#insertionPolicy-prop"><b>insertionPolicy</b></a>&nbsp;- the position of the items inserted by the user</div></li><li><div class=fn>int <a href="#maxCount-prop"><b>maxCount</b></a>&nbsp;- the maximum number of items allowed in the combobox</div></li><li><div class=fn>int <a href="#sizeLimit-prop"><b>sizeLimit</b></a>&nbsp;- the maximum on-screen size of the combobox</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QComboBox widget is a combined button and popup list.<p> <p> A combobox is a selection widget which displays the current item andcan pop up a list of items.  A combobox may be editable in which casethe user can enter arbitrary strings.<p> Since comboboxes occupy little screen space and always display thecurrent item, they are well suited to displaying items that the userwill want to see, such as font family or size. Using a combobox theuser can always see which item they've selected with the minimum amountof screen space being used.<p> QComboBox supports three different display styles: Aqua/Motif 1.x, Motif 2.0and Windows 95.  In Motif 1.x, a combobox was called XmOptionMenu.In Motif 2.0, OSF introduced an improved combobox andnamed that XmComboBox.  QComboBox provides both.<p> QComboBox provides two different constructors.  The simplestconstructor creates an old-style combobox in Motif (or Aqua) style:<pre>      QComboBox *c = new QComboBox( this, "read-only combobox" );  </pre> <p> The other constructor creates a new-style combobox in Motif style, andcan create both read-only and read-write comboboxes:<pre>      QComboBox *c1 = new QComboBox( FALSE, this, "read-only combobox" );      QComboBox *c2 = new QComboBox( TRUE, this, "read-write combobox" );  </pre> <p> New-style comboboxes use a list box in both Motif and Windows styles, andboth the content size and the on-screen size of the list box can belimited with <a href="#sizeLimit">sizeLimit</a>() and <a href="#setMaxCount">setMaxCount</a>() respectively.  Old-stylecomboboxes use a popup in Aqua and Motif style, and that popup willhappily grow larger than the desktop if you put enough data into it.<p> The two constructors create identical-looking comboboxes in Windowsstyle.<p> Comboboxes can contain pixmaps as well as strings; the<a href="#insertItem">insertItem</a>() and <a href="#changeItem">changeItem</a>() functions are suitably overloaded.  Forread-write comboboxes, the function <a href="#clearEdit">clearEdit</a>()is provided, to clear the displayed string without changing thecombobox's contents.<p> A combobox emits two signals, <a href="#activated">activated</a>() and <a href="#highlighted">highlighted</a>(), when anew item has been activated (selected) or highlighted (madecurrent).  Both signals exist in two versions, one with a <a href="qstring.html">QString</a>argument and one with an <tt>int</tt> argument.  If the user highlights oractivates a pixmap, only the <tt>int</tt> signals are emitted. Whenever thetext of an editable combobox is changed the <a href="#textChanged">textChanged</a>() signal isemitted.<p> When the user enters a new string in a read-write combobox, the widgetmay or may not insert it, and it can insert it in several locations.The default policy is is <a href="#Policy-enum">AtBottom</a> but you can change this using<a href="#setInsertionPolicy">setInsertionPolicy</a>().<p> It is possible to constrain the input to an editable combobox using<a href="qvalidator.html">QValidator</a>; see <a href="#setValidator">setValidator</a>().  By default, all input is accepted.<p> If the combo box is not editable then it has a default <a href="qwidget.html#focusPolicy">focusPolicy</a>()of <a href="qwidget.html#FocusPolicy-enum">TabFocus</a>, i.e. it will not grab focus if clicked.  Thisdiffers from both Windows and Motif.  If the combo box is editable then ithas a default focusPolicy() of <a href="qwidget.html#FocusPolicy-enum">StrongFocus</a>, i.e. it will grab focus ifclicked.<p> A combobox can be populated using the insert functions,<a href="#insertStringList">insertStringList</a>() and <a href="#insertItem">insertItem</a>() for example. Items can bechanged with <a href="#changeItem">changeItem</a>(). An item can be removed with <a href="#removeItem">removeItem</a>()and all items can be removed with <a href="#clear">clear</a>(). The text of the currentitem is returned by <a href="#currentText">currentText</a>(), and the text of a numbered itemis returned with <a href="#text">text</a>(). The current item can be set with<a href="#setCurrentItem">setCurrentItem</a>() or <a href="#setCurrentText">setCurrentText</a>(). The number of items in thecombobox is returned by <a href="#count">count</a>(); the maximum number of items can beset with <a href="#setMaxCount">setMaxCount</a>(). You can allow editing using<a href="#setEditable">setEditable</a>(). For editable comboboxes you can set auto-completionusing <a href="#setAutoCompletion">setAutoCompletion</a>() and whether or not the user can add

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?