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

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 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
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on 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 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
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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
          • Vinod KuntojiV Offline
            Vinod KuntojiV Offline
            Vinod Kuntoji
            wrote on 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
            2
            • Vinod KuntojiV Vinod Kuntoji

              @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 last edited by
              #6

              @Vinod-Kuntoji

              not getting setPen in QPalette

              1 Reply Last reply
              0
              • Vinod KuntojiV Offline
                Vinod KuntojiV Offline
                Vinod Kuntoji
                wrote on 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
                0
                • Vinod KuntojiV Vinod Kuntoji

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

                  S Offline
                  S Offline
                  Swapnil_Shelke
                  wrote on last edited by
                  #8

                  @Vinod-Kuntoji

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

                  1 Reply Last reply
                  0

                  • Login

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