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. Subclass of QWizard; setting background in style sheet causes title bar to be blank.
Forum Updated to NodeBB v4.3 + New Features

Subclass of QWizard; setting background in style sheet causes title bar to be blank.

Scheduled Pinned Locked Moved General and Desktop
15 Posts 2 Posters 4.3k Views 2 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #3

    Hi
    Do you call the base class paint ?
    Also to use the setting from a stylesheet, you need to use the methods
    in QStyle to draw. else the stylesheet is not in effect.

    I would try to change its palette
    (in widget)
    QPalette pal = palette();
    pal.setColor(QPalette::Background, Qt::black
    setAutoFillBackground(true);
    setPalette(pal);
    Note it might not use QPalette::Background but some other role.

    P 1 Reply Last reply
    2
    • mrjjM mrjj

      Hi
      Do you call the base class paint ?
      Also to use the setting from a stylesheet, you need to use the methods
      in QStyle to draw. else the stylesheet is not in effect.

      I would try to change its palette
      (in widget)
      QPalette pal = palette();
      pal.setColor(QPalette::Background, Qt::black
      setAutoFillBackground(true);
      setPalette(pal);
      Note it might not use QPalette::Background but some other role.

      P Offline
      P Offline
      Paul Thompson
      wrote on last edited by
      #4

      @mrjj Thanks for the reply.

      Yes, I do call the base class paintEvent, before I do my own painting. I don't understand why that works without setting the style sheet, but then causes the title bar to disappear when I set the style sheet.

      I'll experiment with your suggestion.

      Thanks again.

      mrjjM 1 Reply Last reply
      0
      • P Paul Thompson

        @mrjj Thanks for the reply.

        Yes, I do call the base class paintEvent, before I do my own painting. I don't understand why that works without setting the style sheet, but then causes the title bar to disappear when I set the style sheet.

        I'll experiment with your suggestion.

        Thanks again.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #5

        @Paul-Thompson
        Hi
        Stylesheets are a bit all or nothing
        So when you give it a sheet, some things is no longer drawn.
        So often some images falls off etc. You have to include the styling for those also
        to keep them etc.

        That is why i suggest trying the palette if all you want is change bg color.
        a fast test to see if it will work is just loop over all the roles and set all to say Qt:red

         QPalette bgpal = palette();
            for (int cc=0; cc < QPalette::NColorRoles; cc++ )
            bgpal.setColor (cc, Qt::red);
            setPalette(bgpal);
        
        1 Reply Last reply
        1
        • P Offline
          P Offline
          Paul Thompson
          wrote on last edited by
          #6

          Even setting every color in the palette to the right one doesn't get the background color right. I think I'll just pass on this for now - I don't have the time to fight with this.

          Thanks very much for your help.

          mrjjM 1 Reply Last reply
          0
          • P Paul Thompson

            Even setting every color in the palette to the right one doesn't get the background color right. I think I'll just pass on this for now - I don't have the time to fight with this.

            Thanks very much for your help.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #7

            @Paul-Thompson
            np, i have not self painted a QWizard
            so not sure if it even does paint background or you see something else "behind it"
            Widgets (the actual class) do not have
            setAutoFillBackground(true);
            on pr default.

            Can you post your paint ?
            (even if u skip it for now :)

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Paul Thompson
              wrote on last edited by
              #8

              Sure, here's what's in my paintEvent override:

                  QWizard::paintEvent(event);
              
                  // Paint the banner.
                  QPainter painter(this);
                  const int x{style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + BannerFudge};
                  const int y{style()->pixelMetric(QStyle::PM_TitleBarHeight)};
                  painter.drawImage(x, y, m_banner);
              

              BannerFudge is just a number to line it up right (I'm probably using the wrong PM_* enum to find the width of the edge of the window) and m_banner is of type QImage.

              Thanks for continuing to follow this!

              mrjjM 1 Reply Last reply
              1
              • P Paul Thompson

                Sure, here's what's in my paintEvent override:

                    QWizard::paintEvent(event);
                
                    // Paint the banner.
                    QPainter painter(this);
                    const int x{style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + BannerFudge};
                    const int y{style()->pixelMetric(QStyle::PM_TitleBarHeight)};
                    painter.drawImage(x, y, m_banner);
                

                BannerFudge is just a number to line it up right (I'm probably using the wrong PM_* enum to find the width of the edge of the window) and m_banner is of type QImage.

                Thanks for continuing to follow this!

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @Paul-Thompson said in Subclass of QWizard; setting background in style sheet causes title bar to be blank.:

                QWizard::paintEvent(event)

                I wonder what you really see if from
                void QWizardHeader::paintEvent(QPaintEvent * /* event */)

                If we look at the base drawing, unless
                IsVistaThemeEnabled(QVistaHelper::VistaBasic) is true then
                im not sure it clear bg at all.

                void QWizard::paintEvent(QPaintEvent * event)
                {
                    Q_D(QWizard);
                    if (d->wizStyle == MacStyle && currentPage()) {
                        QPixmap backgroundPixmap = currentPage()->pixmap(BackgroundPixmap);
                        if (backgroundPixmap.isNull())
                            return;
                
                        QPainter painter(this);
                        painter.drawPixmap(0, (height() - backgroundPixmap.height()) / 2, backgroundPixmap);
                    }
                #if QT_CONFIG(style_windowsvista)
                    else if (d->isVistaThemeEnabled()) {
                        if (d->isVistaThemeEnabled(QVistaHelper::VistaBasic)) {
                            QPainter painter(this);
                            QColor color = d->vistaHelper->basicWindowFrameColor();
                            painter.fillRect(0, 0, width(), QVistaHelper::topOffset(), color);
                        }
                        d->vistaHelper->paintEvent(event);
                    }
                #else
                    Q_UNUSED(event);
                #endif
                }
                
                it calls 
                void QVistaHelper::paintEvent(QPaintEvent *event)
                	{
                	    Q_UNUSED(event);
                	    QPainter painter(wizard);
                	    drawTitleBar(&painter);
                	}
                
                in drawTitleBar, it only clear if
                if (vistaState() == VistaAero && isWindow)
                	        drawBlackRect(QRect(0, 0, wizard->width(),
                                            titleBarSize() + topOffset()), hdc);	
                

                So i have this feeling you are seeing through it and its really another widgets background we are after.
                Namely the pages own.
                Since stylesheets are cascading, setting on the Dialog would also affect pages.

                1 Reply Last reply
                1
                • P Offline
                  P Offline
                  Paul Thompson
                  wrote on last edited by
                  #10

                  Thanks - I appreciate the effort, and I'll look into that. I'm setting the background in the pages' style sheets, but I haven't done anything like the experimentation with that that I did with the wizard itself. I'll come to it tomorrow.

                  Again, thanks for spending the time.

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

                    Hi
                    np, i have a hidden agenda as i soon will use the qwizard for a project
                    and i also have other base bg color :)

                    Would it be possible to show image
                    (use postimage.org and post link)
                    To show the actual area that is not getting colored.
                    Just so im 100% sure what you mean as if you set style on the pages
                    it cant be in that area you mean.

                    P 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      Hi
                      np, i have a hidden agenda as i soon will use the qwizard for a project
                      and i also have other base bg color :)

                      Would it be possible to show image
                      (use postimage.org and post link)
                      To show the actual area that is not getting colored.
                      Just so im 100% sure what you mean as if you set style on the pages
                      it cant be in that area you mean.

                      P Offline
                      P Offline
                      Paul Thompson
                      wrote on last edited by
                      #12

                      @mrjj

                      Here you go: https://postimg.org/image/ciz0hsz2t/

                      I've blocked out in red the bits you don't need to see. The green bar is the banner graphic. The dark blue section is the background color as set by the QWizardPages. There are no navigation buttons, as I use custom ones which are in the red bit at the bottom. All the white I can't get to. The top section is the title bar (no text, which is by design). I can't paint onto the other white bits as they are clipped out. It's those bits I need to be the background color. If possible, I'd also like to paint onto them, but I am guessing that is impossible.

                      If you can't see the different colors, let me know and I can number the sections or something.

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

                        Super
                        alt text

                        Those areas i assume.

                        Im pretty sure its not the widget we expect, else your coloring should "hit" it.

                        Using this
                        http://doc.qt.io/qt-5/qtwidgets-dialogs-trivialwizard-example.html

                        should be much like your?
                        Also you did not alter margins or anything like that with stylesheets for the pages?

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

                          Hi
                          Seems to be related to what QStyle used.
                          if i change that with
                          wizard.setWizardStyle(QWizard::WizardStyle::ModernStyle);

                          if u use the test project
                          http://doc.qt.io/qt-5/qtwidgets-dialogs-trivialwizard-example.html

                          and add before .exec()

                            QPalette bgpal = wizard.palette();
                            for (int color = 0; color < QPalette::NColorRoles; color++ ) // just lazy. should use correct roles
                              bgpal.setColor ((QPalette::ColorRole)color, Qt::red);
                          
                            wizard.setWizardStyle(QWizard::WizardStyle::ModernStyle);
                          
                            const QObjectList& list = wizard.children();
                            for (int cc = 0; cc < list.size(); cc++) {
                              QWidget* widget = qobject_cast<QWidget*>(list[cc]);
                              if (!widget) continue; // skip all non widgets
                              widget->setPalette(bgpal);
                            }
                          
                            return app.exec();
                          }
                          

                          alt text

                          Using just
                          wizard.setWizardStyle(QWizard::WizardStyle::ModernStyle);
                          wizard.setStyleSheet("background-color: rgb(255, 255, 0);");

                          i get
                          alt text

                          So it seems to depend on the QStyle used and how much is used from palette and
                          stylesheet to draw the dialog.

                          Your layout of the pages (i have no side margin) seems different so might be other case for you.
                          Maybe even due to using styles on the pages.

                          1 Reply Last reply
                          1
                          • P Offline
                            P Offline
                            Paul Thompson
                            wrote on last edited by
                            #15

                            Thanks for the research. I tried your code and got some slightly different results, even when removing the style sheet from the pages.

                            Using ModernStyle gets the white area which wasn't previously gray to turn gray. However, I lose my custom-painted banner! I've had zero luck using setPixmap to try to get Qt to put in the banner.

                            I think I'm going to live with it for now, as the cosmetic issues here are, frankly, low priority. I think, if I had the luxury of time, I'd implement my own wizard dialog, giving more control to the wizard and its pages. The standard QWizard is great for putting together wizards quickly if you're not too worried about what and where you can paint. My company desires a bit more of a fancy user experience, and QWizard doesn't seem to make that easy.

                            I really appreciate the time you've taken, and I hope you don't run into the same issues I did when you undertake your project.

                            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