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. how to change the left white space which QPainter doesnot draw in QWidget?
Forum Updated to NodeBB v4.3 + New Features

how to change the left white space which QPainter doesnot draw in QWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 651 Views 1 Watching
  • 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.
  • O Offline
    O Offline
    opengpu
    wrote on last edited by opengpu
    #1

    how to change the left white space which QPainter doesnot draw in QWidget?
    i did some drawing in paintEvent, however, the left area which didnot draw remains White, now i want to change this White into the color of its parent's background color which is normally light-gray in windows.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Show the code :)
      or an image at least.
      Its not easy to understand what you mean.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu
        wrote on last edited by opengpu
        #3

        eg.
        void paintEvent()
        {
        ...
        painter.drawRect(rect);//rect is smaller than the QWidget size
        ...
        }
        then the area not belong to rect remains white, and i want to change this white color.

        J.HilkJ 1 Reply Last reply
        0
        • O opengpu

          eg.
          void paintEvent()
          {
          ...
          painter.drawRect(rect);//rect is smaller than the QWidget size
          ...
          }
          then the area not belong to rect remains white, and i want to change this white color.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @opengpu is your widget managed by a QLayout of any kind? Because the "White space" may be just the margins defined in the layout.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • O Offline
            O Offline
            opengpu
            wrote on last edited by
            #5

            no, it's on Layout, but i am sure the white area is the area which i don't draw anything in paintEvent

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by dheerendra
              #6

              Try something like this to fill the white space of your drawing.

              void MyWidget::paintEvent(QPaintEvent*..) {
              ..
              ..
              QRect r = this->rect();
              painter.setBrush(//Set the parent color);
              painter.drawRect(r).// draw the full background first
              painter.setBrush(//Set the current color);
              painter.drawRect(rect);//draw your rect
              
              }
              

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              1
              • O Offline
                O Offline
                opengpu
                wrote on last edited by
                #7

                is this inefficient?

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  opengpu
                  wrote on last edited by
                  #8

                  i tried, and it works, thank you!

                  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