|  | Home · All Classes · Modules

# QGLColormap Class Reference
[QtOpenGL module]

The QGLColormap class is used for installing custom colormaps into QGLWidgets. More...

### Methods

- __init__ (self)
- __init__ (self, QGLColormap)
- detach (self)
- QColor entryColor (self, int idx)
- unsigned long entryRgb (self, int idx)
- int find (self, unsigned long color)
- int findNearest (self, unsigned long color)
- sip.voidptr handle (self)
- bool isEmpty (self)
- setEntries (self, list colors, int base = 0)
- setEntry (self, int idx, unsigned long color)
- setEntry (self, int idx, QColor color)
- setHandle (self, sip.voidptr ahandle)
- int size (self)

## Detailed Description

The QGLColormap class is used for installing custom colormaps into QGLWidgets.

QGLColormap provides a platform independent way of specifying and installing indexed colormaps into QGLWidgets. QGLColormap is especially useful when using the OpenGL color-index mode.

Under X11 you must use an X server that supports either a `PseudoColor` or `DirectColor` visual class. If your X server currently only provides a `GrayScale`, `TrueColor`, `StaticColor` or `StaticGray` visual, you will not be able to allocate colorcells for writing. If this is the case, try setting your X server to 8 bit mode. It should then provide you with at least a `PseudoColor` visual. Note that you may experience colormap flashing if your X server is running in 8 bit mode.

Under Windows the size of the colormap is always set to 256 colors. Note that under Windows you can also install colormaps in child widgets.

This class uses implicit sharing as a memory and speed optimization.

Example of use:

         #include <QApplication>
         #include <QGLColormap>

         int main()
         {
             QApplication app(argc, argv);

             MySuperGLWidget widget;     // a QGLWidget in color-index mode
             QGLColormap colormap;

             // This will fill the colormap with colors ranging from
             // black to white.
             for (int i = 0; i < colormap.size(); i++)
                 colormap.setEntry(i, qRgb(i, i, i));

             widget.setColormap(colormap);
             widget.show();
             return app.exec();
         }

See also QGLWidget.setColormap() and QGLWidget.colormap().

## Method Documentation

### QGLColormap.__init__ (self)

Construct a QGLColormap.

### QGLColormap.__init__ (self, QGLColormap)

Construct a shallow copy of map.

### QGLColormap.detach (self)

### QColor QGLColormap.entryColor (self, int idx)

Returns the QRgb value in the colorcell with index idx.

### unsigned long QGLColormap.entryRgb (self, int idx)

Returns the QRgb value in the colorcell with index idx.

### int QGLColormap.find (self, unsigned long color)

Returns the index of the color color. If color is not in the map, -1 is returned.

### int QGLColormap.findNearest (self, unsigned long color)

Returns the index of the color that is the closest match to color color.

### sip.voidptr QGLColormap.handle (self)

### bool QGLColormap.isEmpty (self)

Returns true if the colormap is empty; otherwise returns false. A colormap with no color values set is considered to be empty.

### QGLColormap.setEntries (self, list colors, int base = 0)

Set an array of cells in this colormap. count is the number of colors that should be set, colors is the array of colors, and base is the starting index.

### QGLColormap.setEntry (self, int idx, unsigned long color)

Set cell at index idx in the colormap to color color.

### QGLColormap.setEntry (self, int idx, QColor color)

This is an overloaded member function, provided for convenience.

Set the cell with index idx in the colormap to color color.

### QGLColormap.setHandle (self, sip.voidptr ahandle)

### int QGLColormap.size (self)

Returns the number of colorcells in the colormap.