Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trying to Draw QRubberBand but QRubberBand not displayed properly
Forum Update on Monday, May 27th 2025

Trying to Draw QRubberBand but QRubberBand not displayed properly

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt 5.8.0qrubberband
8 Posts 4 Posters 3.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Swapnil_Shelke
    wrote on 25 May 2017, 13:12 last edited by
    #1

    Qt version 5.8.0
    Windows 7

    I am drawing a QRubberBand on a QLable, also coloring the QRubberBand Border as Yellow but the whole rectangle is filled with Yellow color.

    I only want the QRubberBand borders to be yellow and not the inside of the QRubberBand
    0_1495717800349_Yellow_rectangle.png

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eddy
      wrote on 25 May 2017, 13:23 last edited by
      #2

      Hi,

      Could you show your code that sets the color to Yellow?

      Eddy

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Swapnil_Shelke
        wrote on 26 May 2017, 04:35 last edited by
        #3

        the following is the code i am using

        dummyband = new QRubberBand(QRubberBand::Rectangle, this);

        QPalette palette;
        //palette.setBrush(QPalette::Foreground, QBrush(color));
        //palette.setBrush(QPalette::Base, QBrush(color));
        palette.setBrush(QPalette::Highlight, QBrush(yellow));
        dummyband->setPalette(palette);
        dummyband->setGeometry(QRect(topLeft, bottomRight));
        dummyband->show();
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 26 May 2017, 05:06 last edited by mrjj
          #4

          Hi
          The docs says

          Rectangle A QRubberBand can represent a rectangle. Some
          styles will interpret this as a filled (often
          semi-transparent) rectangle, or a rectangular
          outline.

          It's also filled on windows 10 so I guess it's by design / also affected by the platform style.

          It draws with QStyle::CE_RubberBand
          so you could override with http://doc.qt.io/qt-5/qproxystyle.html

          class MRubberStyle : public QProxyStyle {
           public:
            MRubberStyle() : QProxyStyle() {}
            ~MRubberStyle() {}
          
            virtual void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0) const {
              switch(element) {
                case CE_RubberBand:
                  // draw as u want
                  return;
                default:
                  QApplication::style()->drawControl(element, option, painter, widget);
              }
            }
          };
          ...
           app.setStyle( new MRubberStyle );
          
          
          1 Reply Last reply
          2
          • V Offline
            V Offline
            Vinod Kuntoji
            wrote on 26 May 2017, 05:17 last edited by
            #5

            @Swapnil_Shelke ,

            You should not use setBrush, it will fill your rectangle with yellow color, Use setPen with yellow color, it will set the yellow border.

            C++, Qt, Qt Quick Developer,
            PthinkS, Bangalore

            S 1 Reply Last reply 26 May 2017, 05:48
            2
            • V Vinod Kuntoji
              26 May 2017, 05:17

              @Swapnil_Shelke ,

              You should not use setBrush, it will fill your rectangle with yellow color, Use setPen with yellow color, it will set the yellow border.

              S Offline
              S Offline
              Swapnil_Shelke
              wrote on 26 May 2017, 05:48 last edited by
              #6

              @Vinod-Kuntoji

              not getting setPen in QPalette

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vinod Kuntoji
                wrote on 26 May 2017, 05:57 last edited by
                #7

                @Swapnil_Shelke ,
                OK. try this,
                rubberBand->setPalette(Qt::transparent);

                C++, Qt, Qt Quick Developer,
                PthinkS, Bangalore

                S 1 Reply Last reply 26 May 2017, 09:00
                0
                • V Vinod Kuntoji
                  26 May 2017, 05:57

                  @Swapnil_Shelke ,
                  OK. try this,
                  rubberBand->setPalette(Qt::transparent);

                  S Offline
                  S Offline
                  Swapnil_Shelke
                  wrote on 26 May 2017, 09:00 last edited by
                  #8

                  @Vinod-Kuntoji

                  No not working ,
                  rubberBand->setPalette(Qt::transparent); removes the color from borders also..

                  1 Reply Last reply
                  0

                  8/8

                  26 May 2017, 09:00

                  • Login

                  • Login or register to search.
                  8 out of 8
                  • First post
                    8/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved