PDA

View Full Version : QRubberBand Color



ToddAtWSU
29th November 2012, 19:06
I have a subclassed QGLWidget called Plot. A couple years ago we tried to use QRubberBand for box selection and box zooming but the QRubberBand didn't display as we hoped. I decided to give it another go-around since nobody is really happy with trying to use OpenGL's XOR drawing for the rubber band. So far, it seems to be working very smoothly and quickly, better than drawing the XOR'd boxes to the front buffer.

Unfortunately, the QRubberBand is defaulted to a black color and our plot's background color is also black. I can tell the box is working when I drag it over other colored objects. I have tried numerous items to change the color of the QRubberBand, but have yet to change its color. Here is some code to show what I have implemented.


void Plot::plotBoxPressed( QMouseEvent* event )
{
if( !mpRubberBand )
{
mpRubberBand = new QRubberBand( QRubberBand::Rectangle, this );
QPalette rbPalette = mpRubberBand->palette( );
rbPalette.setBrush( QPalette::WindowText, Qt::red );
mpRubberBand->setPalette( rbPalette );
}
mRubberBandOrigin = event->pos( );
mpRubberBand->setGeometry( QRect( mRubberBandOrigin, QSize( ) ) );
mpRubberBand->show( );
}

I have also tried numerous items like


rbPalette::setColor( QPalette::WindowText, Qt::red );
rbPalette::setColor( QPalette::Window, Qt::red );
rbPalette::setColor( QPalette::WindowText, QColor( 255, 0, 0 ) );
rbPalette::setBrush( QPalette::WindowText, Qt::red );

but none of these have worked. I have also tried just declaring
QPalette rbPalette; and not saving the existing palette, but none of it seems to work. What am I missing?

Thanks for your help!
Todd

ToddAtWSU
29th November 2012, 22:31
Solved my problem. Apparently QRubberBand needed the following set on its palette:


rbPalette::setBrush( QPalette::Text, QBrush( Qt::red ) );