📄 qbutton.3qt
字号:
'\" t.TH QButton 3qt "5 August 2004" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQButton \- The abstract base class of button widgets, providing functionality common to buttons.br.PP\fC#include <qbutton.h>\fR.PPInherits QWidget..PPInherited by QCheckBox, QPushButton, QRadioButton and QToolButton..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQButton\fR ( QWidget * " "parent" "=0, const char * " "name" "=0, WFlags " "f" "=0 ) ".br.ti -1c.BI "\fB~QButton\fR () ".br.ti -1c.BI "QString \fBtext\fR () const".br.ti -1c.BI "virtual void \fBsetText\fR ( const QString & ) ".br.ti -1c.BI "const QPixmap* \fBpixmap\fR () const".br.ti -1c.BI "virtual void \fBsetPixmap\fR ( const QPixmap & ) ".br.ti -1c.BI "int \fBaccel\fR () const".br.ti -1c.BI "virtual void \fBsetAccel\fR ( int ) ".br.ti -1c.BI "bool \fBisToggleButton\fR () const".br.ti -1c.BI "enum \fBToggleType\fR { SingleShot, Toggle, Tristate }".br.ti -1c.BI "ToggleType \fBtoggleType\fR () const".br.ti -1c.BI "virtual void \fBsetDown\fR ( bool ) ".br.ti -1c.BI "bool \fBisDown\fR () const".br.ti -1c.BI "bool \fBisOn\fR () const".br.ti -1c.BI "enum \fBToggleState\fR { Off, NoChange, On }".br.ti -1c.BI "ToggleState \fBstate\fR () const".br.ti -1c.BI "bool autoResize () const \fI(obsolete)\fR".br.ti -1c.BI "virtual void setAutoResize ( bool ) \fI(obsolete)\fR".br.ti -1c.BI "bool \fBautoRepeat\fR () const".br.ti -1c.BI "virtual void \fBsetAutoRepeat\fR ( bool ) ".br.ti -1c.BI "bool \fBisExclusiveToggle\fR () const".br.ti -1c.BI "QButtonGroup* \fBgroup\fR () const".br.in -1c.SS "Public Slots".in +1c.ti -1c.BI "void \fBanimateClick\fR () ".br.ti -1c.BI "void \fBtoggle\fR () ".br.in -1c.SS "Signals".in +1c.ti -1c.BI "void \fBpressed\fR () ".br.ti -1c.BI "void \fBreleased\fR () ".br.ti -1c.BI "void \fBclicked\fR () ".br.ti -1c.BI "void \fBtoggled\fR ( bool ) ".br.ti -1c.BI "void \fBstateChanged\fR ( int ) ".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "void \fBsetToggleButton\fR ( bool ) ".br.ti -1c.BI "virtual void \fBsetToggleType\fR ( ToggleType ) ".br.ti -1c.BI "void \fBsetOn\fR ( bool ) ".br.ti -1c.BI "virtual void \fBsetState\fR ( ToggleState ) ".br.ti -1c.BI "virtual bool \fBhitButton\fR ( const QPoint & pos ) const".br.ti -1c.BI "virtual void \fBdrawButton\fR ( QPainter * ) ".br.ti -1c.BI "virtual void \fBdrawButtonLabel\fR ( QPainter * ) ".br.ti -1c.BI "virtual void \fBpaintEvent\fR ( QPaintEvent * ) ".br.in -1c.SS "Properties".nf.TSl l l l l- - - - -l l l l l.Type Name READ WRITE OptionsQString text text setTextQPixmap pixmap pixmap setPixmapint accel accel setAccelbool toggleButton isToggleButtonToggleType toggleType toggleTypebool down isDown setDown DESIGNABLE falsebool on isOnToggleState toggleState statebool autoResize autoResize setAutoResizebool autoRepeat autoRepeat setAutoRepeatbool exclusiveToggle isExclusiveToggle.TE.fi.SH DESCRIPTIONThe QButton class is the abstract base class of button widgets, providing functionality common to buttons..PPThe QButton class implements an abstract button, and lets subclasses specify how to reply to user actions and how to draw the button..PPQButton provides both push and toggle buttons. The QRadioButton and QCheckBox classes provide only toggle buttons, QPushButton and QToolButton provide both toggle and push buttons..PPAny button can have either a text or pixmap label. setText() sets the button to be a text button and setPixmap() sets it to be a pixmap button. The text/pixmap is manipulated as necessary to create "disabled" appearance when the button is disabled..PPQButton provides most of the states used for buttons:.TPisDown() determines whether the button is \fIpressed\fR down..TPisOn() determines whether the button is \fIon.\fR Only toggle buttons can be switched on and off (see below)..TPisEnabled() determines whether the button can be pressed by the user..TPsetAutoRepeat() determines whether the button will auto-repeat if the user holds it down..TPsetToggleButton() determines whether the button is a toggle button or not..PPThe difference between isDown() and isOn() is as follows: When the user clicks a toggle button to toggle it on, the button is first \fIpressed,\fR then released into \fIon\fR state. When the user clicks it again (to toggle it off) the button moves first to the \fIpressed\fR state, then to the \fIoff\fR state (isOn() and isDown() are both FALSE)..PPDefault buttons (as used in many dialogs) are provided by QPushButton::setDefault() and QPushButton::setAutoDefault()..PPQButton provides four signals:.TPpressed() is emitted when the left mouse button is pressed while the mouse cursor is inside the button..TPreleased() is emitted when the left mouse button is released..TPclicked() is emitted when the button is first pressed then released, or when the accelerator key is typed, or when animateClick() is called..TPtoggled(bool) is emitted when the state of a toggle button changes..TPstateChanged(int) is emitted when the state of a tristate toggle button changes..PPIf the button is a text button with "&" in its text, QButton creates an automatic accelerator key. This code creates a push button labelled "Rock & Roll" (where the c is underscored). The button gets an automatic accelerator key, Alt-C:.PP.nf.br QPushButton *p = new QPushButton( "Ro&ck && Roll", this );.fi.PPIn this example, when the user presses Alt-C the button will call animateClick()..PPYou can also set a custom accelerator using the setAccel() function. This is useful mostly for pixmap buttons since they have no automatic accelerator..PP.nf.br QPushButton *p;.br p->setPixmap( QPixmap("print.png") );.br p->setAccel( ALT+Key_F7 );.fi.PPAll of the buttons provided by Qt (QPushButton, QToolButton, QCheckBox and QRadioButton) can display both text and pixmaps..PPTo subclass QButton, you have to reimplement at least drawButton() (to draw the button's outskirts) and drawButtonLabel() (to draw its text or pixmap). It is generally advisable to reimplement sizeHint() as well, and sometimes hitButton() (to determine whether a button press is within the button)..PPTo reduce flickering the QButton::paintEvent() sets up a pixmap that the drawButton() function draws in. You should not reimplement paintEvent() for a subclass of QButton unless you want to take over all drawing..PPSee also QButtonGroup..PPExamples:.(lscrollview/scrollview.cpp.)l.SS "Member Type Documentation".SH "QButton::ToggleState"This enum defines the state of a toggle button at any moment. The possible values are: .TP\fCOff\fR - the button is in the "off" state.TP\fCNoChange\fR - the button is in the default/unchanged state.TP\fCOn\fR - the button is in the "on" state.IP.SH "QButton::ToggleType"This enum type defines what a button can do in response to a mouse/keyboard press: .TP\fCSingleShot\fR - pressing the button causes an action, then the button returns to the unpressed state..TP\fCToggle\fR - pressing the button toggles it between an \fCOn\fR and and \fCOff\fR state..TP\fCTristate\fR - pressing the button cycles between the three states \fCOn, Off\fR and \fCNoChange\fR.IP.SH MEMBER FUNCTION DOCUMENTATION.SH "QButton::QButton ( QWidget * parent=0, const char * name=0, WFlags f=0 )"Constructs a standard button with a parent widget and a name..PPIf \fIparent\fR is a QButtonGroup, this constructor calls QButtonGroup::insert()..SH "QButton::~QButton ()"Destructs the button, deleting all its child widgets..SH "int QButton::accel () const"Returns the accelerator key currently set for the button, or 0 if no accelerator key has been set.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -