Name
qsetattribute — set widget attribute
Syntax
qsetattribute [widget] attribute
Description
The qsetattribute command sets a widget attribute. This determines certain behavioral aspects of the widget. The most common attribute is deleteonclose, which ensures that the widget is deleted in memory when closed. See below for a complete list.
Arguments
widget
The target widget. If this argument is omitted the current widget is used.
attribute
The widget attribute to set. The following table lists all attributes.
Table: qwidget attributes
Attribute | Meaning |
---|---|
acceptdrops | Allows data from drag and drop operations to be dropped onto the widget. |
deleteonclose | Makes Qt delete this widget when the widget has accepted the close event. |
quitonclose | Makes Qt quit the application when the last widget with the attribute set has accepted closeEvent(). By default the attribute is set for all widgets with the flag window set. |
keycompression | Enables key event compression if set, and disables it if not set. By default key compression is off, so widgets receive one key press event for each key press (or more, since autorepeat is usually on). If you turn it on and your program doesn't keep up with key input, Qt may try to compress key events so that more than one character can be processed in each event. For example, a word processor widget might receive 2, 3 or more characters in each qkeyevent, if the layout recalculation takes too long for the CPU. If a widget supports multiple character unicode input, it is always safe to turn the compression on. Qt performs key event compression only for printable characters. Qt::Modifier keys, cursor movement keys, function keys and miscellaneous action keys (e.g. Escape, Enter, Backspace, PrintScreen) will stop key event compression, even if there are more compressible key events available. Not all platforms support this compression, in which case turning it on will have no effect. This is set/cleared by the widget's author. |
pendingmoveevent | Indicates that a move event is pending, e.g. when a hidden widget was moved. This is set/cleared by the Qt kernel. |
pendingresizeevent | Indicates that a resize event is pending, e.g. when a hidden widget was resized. This is set/cleared by the Qt kernel. |
undermouse | Indicates that the widget is under the mouse cursor. The value is not updated correctly during drag and drop operations. This is set/cleared by the Qt kernel. |
disabled | Indicates that the widget is disabled, i.e. it does not receive any mouse or keyboard events. . This is set/cleared by the Qt kernel. |
contentspropagated | This flag is superfluous and obsolete; it no longer has any effect. |
forcedisabled | Indicates that the widget is explicitly disabled, i.e. it will remain disabled even when all its ancestors are set to the enabled state. This implies the disabled attribute being set. |
setpalette | Indicates that the widgets has a palette of its own. |
setfont | Indicates that the widgets has a font of its own. |
setcursor | Indicates that the widgets has a cursor of its own. |
nobackground | This value is obsolete. Use opaquepaintevent instead. |
opaquepaintevent | Indicates that the widget paints all its pixels when it receives a paint event. It is thus not required for operations like updating, resizing, scrolling and focus changes to call erase the widget before generating paint events. Using opaquepaintevent is a small optimization. It can help to reduce flicker on systems that do not provide double buffer support, and it avoids the computational cycles necessary to erase the background prior to paint. Note: Unlike the nosystembackground attribute, opaquepaintevent makes an effort to avoid transparent window backgrounds. This is set/cleared by the widget's author. |
nosystembackground | Indicates that the widget has no background, i.e. when the widget receives paint events, the background is not automatically repainted. Note: Unlike opaquepaintevent, newly exposed areas are never filled with the background (e.g after showing a window for the first time the user can see "through" it until the application processes the paint events). Setting this flag implicitly disables double buffering for the widget. This is set/cleared by the widget's author. |
updatesdisabled | Indicates that updates are blocked (including the system background). This flag must never be set/cleared by the widget author. It is set/cleared by the Qt kernel. |
forceupdatesdisabled | Indicates that the widget is explicitly updates disabled, i.e. it will remain disabled even when all its ancestors are set to the updates enabled state. This implies updatesdisabled. |
staticcontents | Indicates that the widget contents are north-west aligned and static. On resize, such a widget will receive paint events only for the newly visible part of itself. This is set/cleared by the widget's author. |
paintonscreen | Indicates that the widget wants to draw directly onto the screen. Widgets with this attribute set do not participate in composition management, i.e. they cannot be semi-transparent or shine through semi-transparent overlapping widgets. This is only supported on X11. The flag is set or cleared by the widget's author. This flag is required for rendering outside of Qt's paint system; e.g. if you need to use native X11 painting primitives. |
paintunclipped | Makes all painters operating on this widget unclipped. Children of this widget or other widgets in front of it do not clip the area the painter can paint on. This flag is only supported on X11 for widgets for which the paintonscreen flag is set. The preferred way to do this in a cross platform way is to create a transparent widget that lies in front of the other widgets. |
paintoutsidepaintevent | Makes it possible to use qpainter to paint on the widget outside paintEvent(). This is not supported on Windows or Mac OS X. We recommend that you use this attribute only when porting Qt 3 code to Qt 4. |
hover | Forces Qt to generate paint events when the mouse enters or leaves the widget. This feature is typically used when implementing custom styles. |
windowmodified | Indicates that the window is marked as modified. On some platforms this will mean nothing, on others (including Mac OS X and Windows) the window will take a modified appearance. |
resized | Indicates that the widget has an explicit size. |
moved | Indicates that the widget has an explicit position. |
mapped | Indicates that the widget is mapped on screen. |
nomousereplay | Used for popup widgets. Indicates that the most recent mouse press event should not be replayed when the popup widget closes. The flag is set by the widget's author and cleared by the Qt kernel every time the widget receives a new mouse event. |
outsidewsrange | Indicates that the widget is outside the valid range of the window system's coordinate system. A widget outside the valid range cannot be mapped on screen. This is set/cleared by the Qt kernel. |
macmetalstyle | Indicates the the widget should be drawn in metal style as supported by the windowing system (only meaningfull on Mac OS X). This is set by widget's author. |
customwhatsthis | Indicates that the widget wants to continue operating normally in What's This mode This is set by the widget's author. |
layoutonentirerect | Indicates that the widget wants qlayout to operate on the entire qwidget rectangle, not only on the qwidgets contentsrectangle. This is set by the widget's author. |
nochildeventsforparent | Indicates that the widget does not want to receive ChildAdded or ChildRemoved events sent from its children. This is set by a widget's author. |
nochildeventsforchildren | Indicates that the widget does not want to receive ChildAdded or ChildRemoved events sent from its children. This is set by a widget's author. |
mousetracking | Indicates that the widget has mouse tracking enabled. |
groupleader | This attribute has been deprecated. |
keyboardfocuschange | Set on a toplevel window when the users changes focus with the keyboard (tab, backtab, or shortcut). |
windowpropagation | Makes a toplevel window inherit font and palette from its parent. |
inputmethodenabled | Enables input methods for asian languages. Must be set when creating custom text editing widgets. |
macnoclickthrough | Indicates that the window is only activated when clicked. |
mousenomask | Makes the widget receive mouse events for the entire widget regardless of the currently set mask. |
nomousepropagation | Prohibits mouse events from being propagated to the widget's parent. |
righttoleft | Indicates that the layout direction for the widget is right to left. |
showmodal | This attribute has been deprecated. |
Examples
Ex.1: qsetattribute
set w [qwidget] qsetattribute deleteonclose qshow $w
The widget 'w' created in the above example has the deleteonclose attribute set, meaning it will be deleted in memory when closed.