# class KTextEditor.Attribute

###

Table of contents
Modules
ktexteditor Classes
All Classes

Module | ktexteditor
Namespace | ktexteditor
Class | KTextEditor.Attribute
Inherits | QTextCharFormat

A class which provides customized text decorations.

The Attribute class extends QTextCharFormat, the class which Qt uses internally to provide formatting information to characters in a text document.

In addition to its inherited properties, it provides support for:

- several customized text formatting properties
- dynamic highlighting of associated ranges of text
- binding of actions with associated ranges of text

Implementations are not required to support all properties. In particular, several properties are not supported for dynamic highlighting (notably: font() and fontBold()).

Unfortunately, as QTextFormat's setProperty() is not virtual, changes that are made to this attribute cannot automatically be redrawn. Once you have finished changing properties, you should call changed() to force redrawing of affected ranges of text.

To do: consider if tracking which ranges use this attribute is needed

See also SmartInterface

Author Hamish Rodda \<rodda@kde.org\>

### enums

- ActivationType = { ActivateMouseIn, ActivateCaretIn }
- CustomProperties = { Outline, SelectedForeground, SelectedBackground, BackgroundFillWhitespace, AttributeDynamicEffect, AttributeInternalProperty, AttributeUserProperty }
- Effect = { EffectNone = 0x0 EffectFadeIn 0x1 EffectFadeOut 0x2 EffectPulse 0x4 EffectCycleGradient 0x8 }
- Effect = { EffectNone, EffectFadeIn, EffectFadeOut, EffectPulse, EffectCycleGradient }

enum details

### methods

- += (a0)

  returns (KTextEditor.Attribute)

  Argument | Type | Default
  --- | --- | ---
  a0 | KTextEditor.Attribute |

- Attribute ()

  returns nothing

  Default constructor. The resulting Attribute has no properties set to begin with.

- Attribute (a)

  returns nothing

  Argument | Type | Default
  --- | --- | ---
  a | KTextEditor.Attribute |

  Copy constructor.

- associateAction (action)

  returns nothing
  Method is not implemented

  Argument | Type | Default
  --- | --- | ---
  action | KAction |

  Action association

  The following functions allow for KAction%s to be associated with attributes, and thus with ranges which use this attribute. \{ Associate an action with this attribute. When assigned to a range, this attribute will enable the associated action(s) when the caret enters the range, and disable them on exit. The action is also added to the context menu when the caret is within an associated range.

  action - KAction to associate with this Attribute

- associatedActions ()

  returns (list of KAction)

  Returns a list of currently associated KAction%s.

- backgroundFillWhitespace ()

  returns (bool)

  Determine whether background color is drawn over whitespace. Defaults to true if not set.

  Returns whether the background color should be drawn over whitespace

- changed ()

  returns nothing
  Method is not implemented

  Notify the editor implementation that a property of this attribute has been changed.

  This is used to re-render any text which has this attribute assigned to it.

- clear ()

  returns nothing

  Clear all set properties.

- clearAssociatedActions ()

  returns nothing

  Clears all associations between KAction%s and this attribute.

- dissociateAction (action)

  returns nothing
  Method is not implemented

  Argument | Type | Default
  --- | --- | ---
  action | KAction |

  Remove the association with an action from this attribute; it will no longer be managed by associated ranges.

  action - KAction to dissociate from this Attribute

- dynamicAttribute (type)

  returns (KTextEditor.Attribute.Ptr)

  Argument | Type | Default
  --- | --- | ---
  type | KTextEditor.Attribute.ActivationType |

  Dynamic highlighting

  The following functions allow for text to be highlighted dynamically based on several events. \{ Return the attribute to use when the event referred to by type occurs.

  type - the activation type for which to return the Attribute.

  \returns the attribute to be used for events specified by type, or null if none is set.

- effects ()

  returns (KTextEditor.Attribute.Effects)

- fontBold ()

  returns (bool)

  Custom properties

  The following functions provide custom properties which can be set for rendering by editor implementations. \{ fontWeight()

  Find out if the font weight is set to QFont.Bold.

  Returns true if the font weight is exactly QFont.Bold, otherwise false

- hasAnyProperty ()

  returns (bool)

  Determine if any properties are set.

  Returns true if any properties are set, otherwise false

- outline ()

  returns (QBrush)

  Get the brush used to draw an outline around text, if any.

  Returns brush to be used to draw an outline, or Qt.NoBrush if no outline is set.

- selectedBackground ()

  returns (QBrush)

  Get the brush used to draw the background of selected text, if any.

  Returns brush to be used to draw the background of selected text, or Qt.NoBrush if not set

- selectedForeground ()

  returns (QBrush)

  Get the brush used to draw text when it is selected, if any.

  Returns brush to be used to draw selected text, or Qt.NoBrush if not set

- setBackgroundFillWhitespace (fillWhitespace)

  returns nothing

  Argument | Type | Default
  --- | --- | ---
  fillWhitespace | bool |

  Set whether background color is drawn over whitespace. Defaults to true if not set.

  Use clearProperty(BackgroundFillWhitespace) to clear.

  fillWhitespace - whether the background should be drawn over whitespace.

- setDynamicAttribute (type, attribute)

  returns nothing

  Argument | Type | Default
  --- | --- | ---
  type | KTextEditor.Attribute.ActivationType |
  attribute | KTextEditor.Attribute.Ptr |

  Set the attribute to use when the event referred to by type occurs.

  Nested dynamic attributes are ignored.

  type - the activation type to set the attribute for

  attribute - the attribute to assign. As attribute is refcounted, ownership is not an issue.

- setEffects (effects)

  returns nothing

  Argument | Type | Default
  --- | --- | ---
  effects | KTextEditor.Attribute.Effects |

- setFontBold (bold)

  returns nothing

  Argument | Type | Default
  --- | --- | ---
  bold | bool | True

  setFontWeight()

  Set the font weight to QFont.Bold. If bold is false, the weight will be set to 0 (normal).

  bold - whether the font weight should be bold or not.

- setOutline (brush)

  returns nothing

  Argument | Type | Default
  --- | --- | ---
  brush | QBrush |

  Set a brush to be used to draw an outline around text.

  Use clearProperty(Outline) to clear.

  brush - brush to be used to draw an outline.

- setSelectedBackground (brush)

  returns nothing

  Argument | Type | Default
  --- | --- | ---
  brush | QBrush |

  Set a brush to be used to draw the background of selected text, if any.

  Use clearProperty(SelectedBackground) to clear.

  brush - brush to be used to draw the background of selected text

- setSelectedForeground (foreground)

  returns nothing

  Argument | Type | Default
  --- | --- | ---
  foreground | QBrush |

  Set a brush to be used to draw selected text.

  Use clearProperty(SelectedForeground) to clear.

  foreground - brush to be used to draw selected text.

### enums - detail

- ActivationType = { ActivateMouseIn, ActivateCaretIn }

  | ActivateMouseIn | - | Activate attribute on mouse in
  | ActivateCaretIn | - | Activate attribute on caret in

- CustomProperties = { Outline, SelectedForeground, SelectedBackground, BackgroundFillWhitespace, AttributeDynamicEffect, AttributeInternalProperty, AttributeUserProperty }

  | Outline | - | Draws an outline around the text
  | SelectedForeground | - | Changes the brush used to paint the text when it is selected
  | SelectedBackground | - | Changes the brush used to paint the background when it is selected
  | BackgroundFillWhitespace | - | Determines whether background color is drawn over whitespace . Defaults to true .
  | AttributeDynamicEffect | - | Defined to allow storage of dynamic effect information
  | AttributeInternalProperty | - | Defined for internal usage of KTextEditor implementations
  | AttributeUserProperty | - | Defined to allow 3 rd party code to create their own custom attributes - you may use values at or above this property .

- Effect = { EffectNone = 0x0 EffectFadeIn 0x1 EffectFadeOut 0x2 EffectPulse 0x4 EffectCycleGradient 0x8 }

  | EffectNone | - | EffectNone = 0x0 < No effect. Just display. , EffectFadeIn = 0x1 < Fade in and stay there. , EffectFadeOut = 0x2 < Fade out to vanish. , EffectPulse = 0x4 < Pulse (throb); change weight. , EffectCycleGradient = 0x8 < Cycle colors.

- Effect = { EffectNone, EffectFadeIn, EffectFadeOut, EffectPulse, EffectCycleGradient }

  | EffectNone | - | EffectNone = 0x0 < No effect. Just display. , EffectFadeIn = 0x1 < Fade in and stay there. , EffectFadeOut = 0x2 < Fade out to vanish. , EffectPulse = 0x4 < Pulse (throb); change weight. , EffectCycleGradient = 0x8 < Cycle colors.