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. Turning off background fill on QDialog
Forum Updated to NodeBB v4.3 + New Features

Turning off background fill on QDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 4.0k 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.
  • C Offline
    C Offline
    Chrisw01
    wrote on last edited by
    #1

    Hi everyone, I have a problem I can't seem to figure out. I have a QDialog which I paint a image on that has transparency in it. When I paint it to the newly created QDialog box I get the image surrounded by a big white square. Apparently QDialog is filling the box with white then my image is painted over it allowing the white to show through the transparency. I have tried setting the setAutoFillBackground() to false no change. If I turn on the WA_TranslucentBackground then the entire image is not drawn. Is there a way to stop the QDialog box from filling itself with a color when created?
    Thanks -- Chris

    kshegunovK 1 Reply Last reply
    0
    • C Chrisw01

      Hi everyone, I have a problem I can't seem to figure out. I have a QDialog which I paint a image on that has transparency in it. When I paint it to the newly created QDialog box I get the image surrounded by a big white square. Apparently QDialog is filling the box with white then my image is painted over it allowing the white to show through the transparency. I have tried setting the setAutoFillBackground() to false no change. If I turn on the WA_TranslucentBackground then the entire image is not drawn. Is there a way to stop the QDialog box from filling itself with a color when created?
      Thanks -- Chris

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Chrisw01

      WA_PaintOnScreen?

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chrisw01
        wrote on last edited by
        #3

        All that did was not display anything and throw errors in the application output box. Here's what I have so far.

        myQDialogBox::DialogBox(QWidget *parent, QString Name) : QDialog(parent) 
        {
              setMouseTracking(false);
              setAutoFillBackground(false); 
              setWindowModality(Qt::ApplicationModal);
              activateWindow();
        
              resize(image->width(), image->Height();
              QPainter p;
              p.setBrush(backgroundRole(), QBrush(*image));
              setPalette(p);
              show();  
        }
        

        It all works fine except it draws a white background before it draws my image and shows through the transparent parts of the image.

        Thanks -- Chris

        kshegunovK 1 Reply Last reply
        0
        • C Chrisw01

          All that did was not display anything and throw errors in the application output box. Here's what I have so far.

          myQDialogBox::DialogBox(QWidget *parent, QString Name) : QDialog(parent) 
          {
                setMouseTracking(false);
                setAutoFillBackground(false); 
                setWindowModality(Qt::ApplicationModal);
                activateWindow();
          
                resize(image->width(), image->Height();
                QPainter p;
                p.setBrush(backgroundRole(), QBrush(*image));
                setPalette(p);
                show();  
          }
          

          It all works fine except it draws a white background before it draws my image and shows through the transparent parts of the image.

          Thanks -- Chris

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Chrisw01
          Hello,

          resize(image->width(), image->Height();
          QPainter p;
          p.setBrush(backgroundRole(), QBrush(*image));
          setPalette(p);
          show();  
          

          You can't do this stuff - neither the painting, nor calling show() - in the constructor. You paint when there's a paint event (i.e. in a QWidget::paintEvent() override), and show() is called from the user of the widget, when the dialog should be shown. But that is after it's fully created.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chrisw01
            wrote on last edited by
            #5

            I somehow don't see moving the code out of the constructor is going to fix the problem. I will try, but i'll lay odds the dialogs still going to be filled with a color which is what I need to avoid since I'm overlaying a QImage with transparency on it.

            kshegunovK 1 Reply Last reply
            0
            • C Chrisw01

              I somehow don't see moving the code out of the constructor is going to fix the problem. I will try, but i'll lay odds the dialogs still going to be filled with a color which is what I need to avoid since I'm overlaying a QImage with transparency on it.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @Chrisw01
              Perhaps I'm in error, I seem to have been misled by the typo (QPainter, where it should've read QPalette). In any case, can you show the relevant part of the code where you actually paint the image?

              I'm sorry I seem to have totally misinterpreted what the problem is. I'm not sure that having a texture pattern for a brush supports an alpha channel though, what do you expect to show under the transparent part of the image?

              Kind regards.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chrisw01
                wrote on last edited by
                #7

                @kshegunov

                My Bad, it was supposed to be QPalette p;

                The part that actually paints the image is

                p.setBrush(BackgroundRole(), QImge(*image));

                Since the dialog is creating a window, it uses the system colors and creates a window filled with the system color (in my case white) then I overlay the QImage on top of it. (BTW I'm creating a Skinable GUI). If I use the WA_TranslucentBackground Attribute, then there is no white filled screen. However because I set background to Translucent then my setBrush fails because I'm painting to the background.

                I would have thought setAutoFillBackground being set to false would have stopped the QDialog from filling its background on creation.

                Here's the code.

                myDialogBox::DialogBox(QWidget *parent, QString Name) : QDialog(parent)
                {
                    setMouseTracking(true);
                    setAutoFillBackground(false);
                    setWindowModality9Qt::ApplicationModal);
                    activateWindow();
                    setWindowFlags(Qt::Dialog | Qt::FramlessWindowHint);
                
                    QPalette p;
                    p.setBrush(BackgroundRole(), QBrush(*Image));
                    setPalette(p);
                
                }
                
                kshegunovK 1 Reply Last reply
                0
                • C Chrisw01

                  @kshegunov

                  My Bad, it was supposed to be QPalette p;

                  The part that actually paints the image is

                  p.setBrush(BackgroundRole(), QImge(*image));

                  Since the dialog is creating a window, it uses the system colors and creates a window filled with the system color (in my case white) then I overlay the QImage on top of it. (BTW I'm creating a Skinable GUI). If I use the WA_TranslucentBackground Attribute, then there is no white filled screen. However because I set background to Translucent then my setBrush fails because I'm painting to the background.

                  I would have thought setAutoFillBackground being set to false would have stopped the QDialog from filling its background on creation.

                  Here's the code.

                  myDialogBox::DialogBox(QWidget *parent, QString Name) : QDialog(parent)
                  {
                      setMouseTracking(true);
                      setAutoFillBackground(false);
                      setWindowModality9Qt::ApplicationModal);
                      activateWindow();
                      setWindowFlags(Qt::Dialog | Qt::FramlessWindowHint);
                  
                      QPalette p;
                      p.setBrush(BackgroundRole(), QBrush(*Image));
                      setPalette(p);
                  
                  }
                  
                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #8

                  @Chrisw01 said:

                  Since the dialog is creating a window

                  Do you mean that you're not passing a parent, or what window if that's not what you mean?

                  I would have thought setAutoFillBackground being set to false would have stopped the QDialog from filling its background on creation.

                  But even if that were the case, then setting a brush for the background would do nothing, wouldn't it?

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Chrisw01
                    wrote on last edited by
                    #9

                    Yes, I am passing it a parent, however the QDialog creates a new window on top of your current window. I pretty much have given up on this now, I even went as far as overloading the paintEvent for the dialog class and painting from within with the same outcome. And perhaps I misunderstood the setAutoFillBackground, I figured its purpose was to fill the background of the window. So for now I'll just remove the transparent section and it works fine.

                    Thanks!!

                    kshegunovK 1 Reply Last reply
                    0
                    • C Chrisw01

                      Yes, I am passing it a parent, however the QDialog creates a new window on top of your current window. I pretty much have given up on this now, I even went as far as overloading the paintEvent for the dialog class and painting from within with the same outcome. And perhaps I misunderstood the setAutoFillBackground, I figured its purpose was to fill the background of the window. So for now I'll just remove the transparent section and it works fine.

                      Thanks!!

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #10

                      @Chrisw01

                      Yes, I am passing it a parent, however the QDialog creates a new window on top of your current window.

                      It doesn't create a new window when you pass a parent; Qt's widgets are alien by default. That's why I was asking. If the dialog is a child widget and it doesn't paint anything it will let you see the parent's contents.

                      Read and abide by the Qt Code of Conduct

                      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