Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, July 1999
100 shades of grey II


Message 1 in thread

Hi again,

The two answers I got (Thank you!) so far

>   QColor *c[100];
>   int a, n;
> 
>   for(a=0;a<100;a++) 

>     n = (int)((255.0 / 100.0) * a);
or 
>     n = (int)(0.5 + 255*pow(a / 100.0, 0.45));

>     c[a] = new QColor( n, n, n );

seem to solve the problem of course. But the following should work as
well:

    #include <new.h>
    int graysize = 101;
    const char *cc;
    grayscale = ( QColor* )new QColor[ sizeof(QColor)*graysize ];
    for ( i = 0; i < graysize; ++i )
    {
      cc = ( const char* )( String( "Gray" ) + incore( i ) );
#ifdef TOOLBOX_RAINBOW_DEBUG
      cout << "Rainbow: cc = " << cc << endl;
#endif
      new( grayscale + i ) QColor( cc );
    }   

The RGB values of the color database should already take gamma
correction into account.
Note that the problem is not in my String class, because cout << cc
outputs the values Gray0 ... Gray100 as it should and cc is of const
char* type as it should.

I think that this is valid C++ and that Qt allocates too many colors by
default so that there are no 101 colorcells left. Therefore I get only a
few shades.

Could somebody comment on how to get precise colors?

Thank you again to those who answered!

Stefan


Message 2 in thread

On Jul 29, 10:37pm, Stefan Link wrote:
> Subject: 100 shades of grey II
> Hi again,
> seem to solve the problem of course. But the following should work as
> well:
>
>     #include <new.h>
>     int graysize = 101;
>     const char *cc;
>     grayscale = ( QColor* )new QColor[ sizeof(QColor)*graysize ];

If youre allocating an array of QColors, you don't have to take sizeof(QColor)
into account. new QColor[graysize] will give you enough space for graysize
QColors. (new QColor[1] will give the enough space for 1 QColor)




>     for ( i = 0; i < graysize; ++i )
>     {
>       cc = ( const char* )( String( "Gray" ) + incore( i ) );
> #ifdef TOOLBOX_RAINBOW_DEBUG
>       cout << "Rainbow: cc = " << cc << endl;
> #endif
>       new( grayscale + i ) QColor( cc );
>     }
>
>-- End of excerpt from Stefan Link



-- 
 [ signature omitted ] 

Message 3 in thread

>I think that this is valid C++ and that Qt allocates too many colors by
>default so that there are no 101 colorcells left. Therefore I 
>get only a
>few shades.

It's not Qt -- probably Netscape or KDE. Run Netscape as:

netscape -install (you'll get color-flashing)
or
netscape -ncols 32 (pages will appear washed-out)

If you're using KDE, turn off the fancy, shaded titlebars
as they suck up the colorcells.

Better yet, set your X server to use a deeper default visual.
32bpp truecolor looks great but a 16bpp truecolor visual is
adequate for almost anything.

Read "X Window System User's Guide" (Valerie Quercia and Tim
O'Reilly), O'Reilly and Associates, Chapter 12. This will
teach all you need to know about X color allocation.

:P

Message 4 in thread


I had the same problem. Try calling this before creating your QApplication


QApplication::setColorSpec(QApplication::ManyColor);


On Jul 29,  5:17pm, PAT_WARD@HP-USA-om5.om.hp.com wrote:
> Subject: RE: 100 shades of grey II
>
> >I think that this is valid C++ and that Qt allocates too many colors by
> >default so that there are no 101 colorcells left. Therefore I
> >get only a
> >few shades.
>
> It's not Qt -- probably Netscape or KDE. Run Netscape as:
>
> netscape -install (you'll get color-flashing)
> or
> netscape -ncols 32 (pages will appear washed-out)
>
> If you're using KDE, turn off the fancy, shaded titlebars
> as they suck up the colorcells.
>
> Better yet, set your X server to use a deeper default visual.
> 32bpp truecolor looks great but a 16bpp truecolor visual is
> adequate for almost anything.
>
> Read "X Window System User's Guide" (Valerie Quercia and Tim
> O'Reilly), O'Reilly and Associates, Chapter 12. This will
> teach all you need to know about X color allocation.
>
> :P
>-- End of excerpt from PAT_WARD@HP-USA-om5.om.hp.com



-- 
 [ signature omitted ]