.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.grid.GridCellAttr:

==========================================================================================================================================
|phoenix_title|  **wx.grid.GridCellAttr**
==========================================================================================================================================

This class can be used to alter the cells' appearance in the grid by changing their attributes from the defaults.          

An object of this class may be returned by :meth:`wx.grid.GridTableBase.GetAttr` . 

Note that objects of this class are reference-counted and it's recommended to use GridCellAttrPtr smart pointer class when working with them to avoid memory leaks. 









|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>GridCellAttr</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.grid.GridCellAttr_inheritance.png" alt="Inheritance diagram of GridCellAttr" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.grid.GridCellAttr.html" title="wx.grid.GridCellAttr" alt="" coords="104,83,255,112"/> <area shape="rect" id="node2" href="wx.ClientDataContainer.html" title="wx.ClientDataContainer" alt="" coords="5,5,183,35"/> <area shape="rect" id="node3" href="wx.RefCounter.html" title="wx.RefCounter" alt="" coords="207,5,325,35"/> </map> 
   </p>
   </div>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.grid.GridCellAttr.__init__`                                           Default constructor.
:meth:`~wx.grid.GridCellAttr.CanOverflow`                                        Returns ``True`` if the cell will draw an overflowed text into the neighbouring cells.
:meth:`~wx.grid.GridCellAttr.Clone`                                              Creates a new copy of this object.
:meth:`~wx.grid.GridCellAttr.DecRef`                                             This class is reference counted: it is created with ref count of 1, so calling :meth:`~GridCellAttr.DecRef`   once will delete it.
:meth:`~wx.grid.GridCellAttr.GetAlignment`                                       Get the alignment to use for the cell with the given attribute.
:meth:`~wx.grid.GridCellAttr.GetBackgroundColour`                                Returns the background colour.
:meth:`~wx.grid.GridCellAttr.GetEditor`                                          Returns the cell editor.
:meth:`~wx.grid.GridCellAttr.GetEditorPtr`                                       Returns the cell editor.
:meth:`~wx.grid.GridCellAttr.GetFitMode`                                         Returns the fitting mode for the cells using this attribute.
:meth:`~wx.grid.GridCellAttr.GetFont`                                            Returns the font.
:meth:`~wx.grid.GridCellAttr.GetKind`                                            
:meth:`~wx.grid.GridCellAttr.GetNonDefaultAlignment`                             Get the alignment defined by this attribute.
:meth:`~wx.grid.GridCellAttr.GetOverflow`                                        Returns ``True`` if the cells using this attribute overflow into the neighbouring cells.
:meth:`~wx.grid.GridCellAttr.GetRenderer`                                        Returns the cell renderer.
:meth:`~wx.grid.GridCellAttr.GetRendererPtr`                                     Returns the cell editor.
:meth:`~wx.grid.GridCellAttr.GetSize`                                            
:meth:`~wx.grid.GridCellAttr.GetTextColour`                                      Returns the text colour.
:meth:`~wx.grid.GridCellAttr.HasAlignment`                                       Returns ``True`` if this attribute has a valid alignment set.
:meth:`~wx.grid.GridCellAttr.HasBackgroundColour`                                Returns ``True`` if this attribute has a valid background colour set.
:meth:`~wx.grid.GridCellAttr.HasEditor`                                          Returns ``True`` if this attribute has a valid cell editor set.
:meth:`~wx.grid.GridCellAttr.HasFont`                                            Returns ``True`` if this attribute has a valid font set.
:meth:`~wx.grid.GridCellAttr.HasOverflowMode`                                    
:meth:`~wx.grid.GridCellAttr.HasReadWriteMode`                                   
:meth:`~wx.grid.GridCellAttr.HasRenderer`                                        Returns ``True`` if this attribute has a valid cell renderer set.
:meth:`~wx.grid.GridCellAttr.HasSize`                                            
:meth:`~wx.grid.GridCellAttr.HasTextColour`                                      Returns ``True`` if this attribute has a valid text colour set.
:meth:`~wx.grid.GridCellAttr.IncRef`                                             This class is reference counted: it is created with ref count of 1, so calling :meth:`~GridCellAttr.DecRef`   once will delete it.
:meth:`~wx.grid.GridCellAttr.IsReadOnly`                                         Returns ``True`` if this cell is set as read-only.
:meth:`~wx.grid.GridCellAttr.MergeWith`                                          
:meth:`~wx.grid.GridCellAttr.SetAlignment`                                       Sets the alignment.
:meth:`~wx.grid.GridCellAttr.SetBackgroundColour`                                Sets the background colour.
:meth:`~wx.grid.GridCellAttr.SetDefAttr`                                         
:meth:`~wx.grid.GridCellAttr.SetEditor`                                          Sets the editor to be used with the cells with this attribute.
:meth:`~wx.grid.GridCellAttr.SetFitMode`                                         Specifies the behaviour of the cell contents if it doesn't fit into the available space.
:meth:`~wx.grid.GridCellAttr.SetFont`                                            Sets the font.
:meth:`~wx.grid.GridCellAttr.SetKind`                                            
:meth:`~wx.grid.GridCellAttr.SetOverflow`                                        Specifies if cells using this attribute should overflow or clip their contents.
:meth:`~wx.grid.GridCellAttr.SetReadOnly`                                        Sets the cell as read-only.
:meth:`~wx.grid.GridCellAttr.SetRenderer`                                        Sets the renderer to be used for cells with this attribute.
:meth:`~wx.grid.GridCellAttr.SetSize`                                            
:meth:`~wx.grid.GridCellAttr.SetTextColour`                                      Sets the text colour.
:meth:`~wx.grid.GridCellAttr.~wxGridCellAttr`                                    The destructor is private because only :meth:`~GridCellAttr.DecRef`   can delete us.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.grid.GridCellAttr.BackgroundColour`                                   See :meth:`~wx.grid.GridCellAttr.GetBackgroundColour` and :meth:`~wx.grid.GridCellAttr.SetBackgroundColour`
:attr:`~wx.grid.GridCellAttr.FitMode`                                            See :meth:`~wx.grid.GridCellAttr.GetFitMode` and :meth:`~wx.grid.GridCellAttr.SetFitMode`
:attr:`~wx.grid.GridCellAttr.Font`                                               See :meth:`~wx.grid.GridCellAttr.GetFont` and :meth:`~wx.grid.GridCellAttr.SetFont`
:attr:`~wx.grid.GridCellAttr.Kind`                                               See :meth:`~wx.grid.GridCellAttr.GetKind` and :meth:`~wx.grid.GridCellAttr.SetKind`
:attr:`~wx.grid.GridCellAttr.Overflow`                                           See :meth:`~wx.grid.GridCellAttr.GetOverflow` and :meth:`~wx.grid.GridCellAttr.SetOverflow`
:attr:`~wx.grid.GridCellAttr.TextColour`                                         See :meth:`~wx.grid.GridCellAttr.GetTextColour` and :meth:`~wx.grid.GridCellAttr.SetTextColour`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.grid.GridCellAttr(ClientDataContainer, RefCounter)

   **Possible constructors**::

       GridCellAttr(attrDefault=None)
       
       GridCellAttr(colText, colBack, font, hAlign, vAlign)
       
   
   This class can be used to alter the cells' appearance in the grid by
   changing their attributes from the defaults.



   .. method:: __init__(self, *args, **kw)



      |overload| Overloaded Implementations:

      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, attrDefault=None)`
      
      Default constructor.                  
      
      
      :param `attrDefault`: 
      :type `attrDefault`: wx.grid.GridCellAttr
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`

      
      **__init__** `(self, colText, colBack, font, hAlign, vAlign)`
      
      Constructor specifying some of the often used attributes.                  
      
      
      :param `colText`: 
      :type `colText`: wx.Colour
      :param `colBack`: 
      :type `colBack`: wx.Colour
      :param `font`: 
      :type `font`: wx.Font
      :param `hAlign`: 
      :type `hAlign`: int
      :param `vAlign`: 
      :type `vAlign`: int
      
      
      
      
      
      
      :html:`<hr class="overloadsep" /><br />`






   .. method:: CanOverflow(self)

      Returns ``True`` if the cell will draw an overflowed text into the neighbouring cells.                  

      Note that only left aligned cells currently can overflow. It means that :meth:`GetFitMode` .IsOverflow() should returns ``True`` and GetAlignment should returns ``wx.ALIGN_LEFT`` for hAlign parameter. 

                

      :rtype: `bool`







      .. versionadded:: 4.1/wxWidgets-3.1.4  
     








   .. method:: Clone(self)

      Creates a new copy of this object.                  

      :rtype: :ref:`wx.grid.GridCellAttr`








   .. method:: DecRef(self)

      This class is reference counted: it is created with ref count of 1, so calling :meth:`DecRef`   once will delete it.                  

      Calling :meth:`IncRef`   allows locking it until the matching :meth:`DecRef`   is called.                   





   .. method:: GetAlignment(self)

      Get the alignment to use for the cell with the given attribute.                  

      If this attribute doesn't specify any alignment, the default attribute alignment is used (which can be changed using :meth:`wx.grid.Grid.SetDefaultCellAlignment`   but is left and top by default). 

      Notice that `hAlign`  and `vAlign`  values are always overwritten by this function, use :meth:`GetNonDefaultAlignment`   if this is not desirable. 







      :rtype: `tuple`



                  



      :returns: 

         ( `hAlign`, `vAlign` ) 








   .. method:: GetBackgroundColour(self)

      Returns the background colour.                  

      :rtype: :ref:`Colour`








   .. method:: GetEditor(self, grid, row, col)

      Returns the cell editor.                  

      The caller is responsible for calling :meth:`DecRef`   on the returned pointer, use :meth:`GetEditorPtr`   to do it automatically.                  


      :param `grid`: 
      :type `grid`: wx.grid.Grid
      :param `row`: 
      :type `row`: int
      :param `col`: 
      :type `col`: int




      :rtype: :ref:`wx.grid.GridCellEditor`








   .. method:: GetEditorPtr(self, grid, row, col)

      Returns the cell editor.                  

      This method is identical to :meth:`GetEditor` , but returns a smart pointer, which frees the caller from the need to call :meth:`DecRef`   manually. 

                


      :param `grid`: 
      :type `grid`: wx.grid.Grid
      :param `row`: 
      :type `row`: int
      :param `col`: 
      :type `col`: int




      :rtype: :ref:`wx.grid.GridCellEditorPtr`







      .. versionadded:: 4.1/wxWidgets-3.1.4  
     








   .. method:: GetFitMode(self)

      Returns the fitting mode for the cells using this attribute.                  

      The returned :ref:`wx.grid.GridFitMode`  is always specified, i.e. :meth:`wx.grid.GridFitMode.IsSpecified`   always returns ``True``. The default value, if :meth:`SetFitMode`   hadn't been called before, is "overflow". 

                

      :rtype: :ref:`wx.grid.GridFitMode`







      .. versionadded:: 4.1/wxWidgets-3.1.4  
     








   .. method:: GetFont(self)

      Returns the font.                  

      :rtype: :ref:`Font`








   .. method:: GetKind(self)



      :rtype: :ref:`wx.grid.GridCellAttr.AttrKind`








   .. method:: GetNonDefaultAlignment(self)

      Get the alignment defined by this attribute.                  

      Unlike :meth:`GetAlignment`   this function only modifies `hAlign`  and `vAlign`  if this attribute does define a non-default alignment. This means that they must be initialized before calling this function and that their values will be preserved unchanged if they are different from ``wx.ALIGN_INVALID``. 

      For example, the following fragment can be used to use the cell alignment if one is defined but right-align its contents by default (instead of left-aligning it by default) while still using the default vertical alignment: ::

          hAlign = wx.ALIGN_RIGHT
          vAlign = wx.ALIGN_INVALID

          hAlign, vAlign = attr.GetNonDefaultAlignment()



                

      :rtype: `tuple`







      :returns: 

         ( `hAlign`, `vAlign` ) 







      .. versionadded:: 2.9.1 
     








   .. method:: GetOverflow(self)

      Returns ``True`` if the cells using this attribute overflow into the neighbouring cells.                  

      Prefer using :meth:`GetFitMode`   in the new code.                  

      :rtype: `bool`








   .. method:: GetRenderer(self, grid, row, col)

      Returns the cell renderer.                  

      The caller is responsible for calling :meth:`DecRef`   on the returned pointer, use :meth:`GetRendererPtr`   to do it automatically.                  


      :param `grid`: 
      :type `grid`: wx.grid.Grid
      :param `row`: 
      :type `row`: int
      :param `col`: 
      :type `col`: int




      :rtype: :ref:`wx.grid.GridCellRenderer`








   .. method:: GetRendererPtr(self, grid, row, col)

      Returns the cell editor.                  

      This method is identical to :meth:`GetRenderer` , but returns a smart pointer, which frees the caller from the need to call :meth:`DecRef`   manually. 

                


      :param `grid`: 
      :type `grid`: wx.grid.Grid
      :param `row`: 
      :type `row`: int
      :param `col`: 
      :type `col`: int




      :rtype: :ref:`wx.grid.GridCellRendererPtr`







      .. versionadded:: 4.1/wxWidgets-3.1.4  
     








   .. method:: GetSize(self)



      :rtype: `tuple`







      :returns: 

         ( `num_rows`, `num_cols` ) 








   .. method:: GetTextColour(self)

      Returns the text colour.                  

      :rtype: :ref:`Colour`








   .. method:: HasAlignment(self)

      Returns ``True`` if this attribute has a valid alignment set.                  

      :rtype: `bool`








   .. method:: HasBackgroundColour(self)

      Returns ``True`` if this attribute has a valid background colour set.                  

      :rtype: `bool`








   .. method:: HasEditor(self)

      Returns ``True`` if this attribute has a valid cell editor set.                  

      :rtype: `bool`








   .. method:: HasFont(self)

      Returns ``True`` if this attribute has a valid font set.                  

      :rtype: `bool`








   .. method:: HasOverflowMode(self)



      :rtype: `bool`








   .. method:: HasReadWriteMode(self)



      :rtype: `bool`








   .. method:: HasRenderer(self)

      Returns ``True`` if this attribute has a valid cell renderer set.                  

      :rtype: `bool`








   .. method:: HasSize(self)



      :rtype: `bool`








   .. method:: HasTextColour(self)

      Returns ``True`` if this attribute has a valid text colour set.                  

      :rtype: `bool`








   .. method:: IncRef(self)

      This class is reference counted: it is created with ref count of 1, so calling :meth:`DecRef`   once will delete it.                  

      Calling :meth:`IncRef`   allows locking it until the matching :meth:`DecRef`   is called.                   





   .. method:: IsReadOnly(self)

      Returns ``True`` if this cell is set as read-only.                  

      :rtype: `bool`








   .. method:: MergeWith(self, mergefrom)




      :param `mergefrom`: 
      :type `mergefrom`: wx.grid.GridCellAttr







   .. method:: SetAlignment(self, hAlign, vAlign)

      Sets the alignment.                  

      `hAlign`  can be one of  ``ALIGN_LEFT`` ,   ``ALIGN_CENTRE``   or   ``ALIGN_RIGHT``   and  `vAlign`  can be one of  ``ALIGN_TOP`` ,   ``ALIGN_CENTRE``   or   ``ALIGN_BOTTOM`` .                   


      :param `hAlign`: 
      :type `hAlign`: int
      :param `vAlign`: 
      :type `vAlign`: int







   .. method:: SetBackgroundColour(self, colBack)

      Sets the background colour.                  


      :param `colBack`: 
      :type `colBack`: wx.Colour







   .. method:: SetDefAttr(self, defAttr)



                


      :param `defAttr`: 
      :type `defAttr`: wx.grid.GridCellAttr






      .. todo:: Needs documentation.    








   .. method:: SetEditor(self, editor)

      Sets the editor to be used with the cells with this attribute.                  


      :param `editor`: 
      :type `editor`: wx.grid.GridCellEditor







   .. method:: SetFitMode(self, fitMode)

      Specifies the behaviour of the cell contents if it doesn't fit into the available space.                  

                


      :param `fitMode`: 
      :type `fitMode`: wx.grid.GridFitMode






      .. versionadded:: 4.1/wxWidgets-3.1.4  
     







      .. seealso:: :ref:`wx.grid.GridFitMode`  








   .. method:: SetFont(self, font)

      Sets the font.                  


      :param `font`: 
      :type `font`: wx.Font







   .. method:: SetKind(self, kind)




      :param `kind`: 
      :type `kind`: wx.grid.GridCellAttr.AttrKind







   .. method:: SetOverflow(self, allow=True)

      Specifies if cells using this attribute should overflow or clip their contents.                  

      This is the same as calling :meth:`SetFitMode`   with either :meth:`wx.grid.GridFitMode.Overflow`   or :meth:`wx.grid.GridFitMode.Clip`   argument depending on whether `allow`  is ``True`` or ``False``. 

      Prefer using :meth:`SetFitMode`   directly instead in the new code.                  


      :param `allow`: 
      :type `allow`: bool







   .. method:: SetReadOnly(self, isReadOnly=True)

      Sets the cell as read-only.                  


      :param `isReadOnly`: 
      :type `isReadOnly`: bool







   .. method:: SetRenderer(self, renderer)

      Sets the renderer to be used for cells with this attribute.                  

      Takes ownership of the pointer.                  


      :param `renderer`: 
      :type `renderer`: wx.grid.GridCellRenderer







   .. method:: SetSize(self, num_rows, num_cols)




      :param `num_rows`: 
      :type `num_rows`: int
      :param `num_cols`: 
      :type `num_cols`: int







   .. method:: SetTextColour(self, colText)

      Sets the text colour.                  


      :param `colText`: 
      :type `colText`: wx.Colour







   .. method:: ~wxGridCellAttr(self)

      The destructor is private because only :meth:`DecRef`   can delete us.                   





   .. attribute:: BackgroundColour

      See :meth:`~wx.grid.GridCellAttr.GetBackgroundColour` and :meth:`~wx.grid.GridCellAttr.SetBackgroundColour`


   .. attribute:: FitMode

      See :meth:`~wx.grid.GridCellAttr.GetFitMode` and :meth:`~wx.grid.GridCellAttr.SetFitMode`


   .. attribute:: Font

      See :meth:`~wx.grid.GridCellAttr.GetFont` and :meth:`~wx.grid.GridCellAttr.SetFont`


   .. attribute:: Kind

      See :meth:`~wx.grid.GridCellAttr.GetKind` and :meth:`~wx.grid.GridCellAttr.SetKind`


   .. attribute:: Overflow

      See :meth:`~wx.grid.GridCellAttr.GetOverflow` and :meth:`~wx.grid.GridCellAttr.SetOverflow`


   .. attribute:: TextColour

      See :meth:`~wx.grid.GridCellAttr.GetTextColour` and :meth:`~wx.grid.GridCellAttr.SetTextColour`


.. toctree::
   :maxdepth: 1
   :hidden:

   wx.grid.GridCellAttr.AttrKind.enumeration
