Results 1 to 2 of 2

Thread: QRubberBand Color

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question QRubberBand Color

    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.

    Qt Code:
    1. void Plot::plotBoxPressed( QMouseEvent* event )
    2. {
    3. if( !mpRubberBand )
    4. {
    5. mpRubberBand = new QRubberBand( QRubberBand::Rectangle, this );
    6. QPalette rbPalette = mpRubberBand->palette( );
    7. rbPalette.setBrush( QPalette::WindowText, Qt::red );
    8. mpRubberBand->setPalette( rbPalette );
    9. }
    10. mRubberBandOrigin = event->pos( );
    11. mpRubberBand->setGeometry( QRect( mRubberBandOrigin, QSize( ) ) );
    12. mpRubberBand->show( );
    13. }
    To copy to clipboard, switch view to plain text mode 

    I have also tried numerous items like

    Qt Code:
    1. rbPalette::setColor( QPalette::WindowText, Qt::red );
    2. rbPalette::setColor( QPalette::Window, Qt::red );
    3. rbPalette::setColor( QPalette::WindowText, QColor( 255, 0, 0 ) );
    4. rbPalette::setBrush( QPalette::WindowText, Qt::red );
    To copy to clipboard, switch view to plain text mode 

    but none of these have worked. I have also tried just declaring
    Qt Code:
    1. QPalette rbPalette;
    To copy to clipboard, switch view to plain text mode 
    and not saving the existing palette, but none of it seems to work. What am I missing?

    Thanks for your help!
    Todd

  2. #2
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Thumbs up Re: QRubberBand Color

    Solved my problem. Apparently QRubberBand needed the following set on its palette:

    Qt Code:
    1. rbPalette::setBrush( QPalette::Text, QBrush( Qt::red ) );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Change the color of QRubberBand
    By franco.amato in forum Qt Programming
    Replies: 14
    Last Post: 4th August 2011, 16:30
  2. How to draw QRubberBand with red color
    By lni in forum Qt Programming
    Replies: 15
    Last Post: 10th March 2010, 09:49
  3. Replies: 1
    Last Post: 30th October 2009, 20:02
  4. Use of QRubberBand
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2009, 12:59
  5. Using QRubberBand class?!?!?
    By nupul in forum Newbie
    Replies: 3
    Last Post: 1st April 2006, 17:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.