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. QGraphicsColorizeEffect resizes widgets
Forum Updated to NodeBB v4.3 + New Features

QGraphicsColorizeEffect resizes widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 864 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.
  • J Offline
    J Offline
    Jakob Clausen
    wrote on last edited by
    #1

    Hi all.
    I have a vertical navigation menu with six navigation buttons. The height of the navigation menu is exactly six times the height of one button. Both buttons and menu is set to a fixed size.
    The menu looks like this.
    before.png
    The top button has a lighter color. Unfortunately the others are a little diffucult to see. If I put a QGraphicsColorizeEffect on the menu. Then it looks like this.
    after.png
    The Graphics effect is there, but only three buttons remain.
    I actually set the effect before the first picture, and then i set the strength to zero (which I assume looks the same as no effect?). In the second picture I set the strength to higher than zero.
    If I reset the strength to zero, then the effect disappears - as expected - but still only three buttons remain.
    The code of the base class looks like this:

    #include "TargetFocus.h"
    #include "UI.h"
    #include <QGraphicsColorizeEffect>
    #include <QDebug>
    
    #define ACTIVATE        0.2
    #define DEACTIVATE      0
    #define ACTIVE_COLOR    "blue" //0x272727
    
    TargetFocus::TargetFocus(QWidget *parent, UI& ui, MainFocus::Position position) :
        QWidget{parent},
        effect(new QGraphicsColorizeEffect),
        position(position)
    {
        effect->setColor(ACTIVE_COLOR);
        effect->setStrength(DEACTIVATE);
        setGraphicsEffect(effect);
        connect(ui.mainFocus, &MainFocus::choose, this, &TargetFocus::choose);
    }
    
    void TargetFocus::choose(MainFocus::Position target)
    {
        if (position == target)
            qDebug() << position;
    
        if (position == target)
            effect->setStrength(ACTIVATE);
        else
            effect->setStrength(DEACTIVATE);
    }
    
    

    When I run the program, then I get a lot of.

    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    

    As application output. These outputs seems to be related to the function call setGraphicsEffect(effect). If I remove that line, then of course nothing happens, but I also do not get these QPainter messages.

    What do you think I should do?

    J 1 Reply Last reply
    0
    • J Jakob Clausen

      Hi all.
      I have a vertical navigation menu with six navigation buttons. The height of the navigation menu is exactly six times the height of one button. Both buttons and menu is set to a fixed size.
      The menu looks like this.
      before.png
      The top button has a lighter color. Unfortunately the others are a little diffucult to see. If I put a QGraphicsColorizeEffect on the menu. Then it looks like this.
      after.png
      The Graphics effect is there, but only three buttons remain.
      I actually set the effect before the first picture, and then i set the strength to zero (which I assume looks the same as no effect?). In the second picture I set the strength to higher than zero.
      If I reset the strength to zero, then the effect disappears - as expected - but still only three buttons remain.
      The code of the base class looks like this:

      #include "TargetFocus.h"
      #include "UI.h"
      #include <QGraphicsColorizeEffect>
      #include <QDebug>
      
      #define ACTIVATE        0.2
      #define DEACTIVATE      0
      #define ACTIVE_COLOR    "blue" //0x272727
      
      TargetFocus::TargetFocus(QWidget *parent, UI& ui, MainFocus::Position position) :
          QWidget{parent},
          effect(new QGraphicsColorizeEffect),
          position(position)
      {
          effect->setColor(ACTIVE_COLOR);
          effect->setStrength(DEACTIVATE);
          setGraphicsEffect(effect);
          connect(ui.mainFocus, &MainFocus::choose, this, &TargetFocus::choose);
      }
      
      void TargetFocus::choose(MainFocus::Position target)
      {
          if (position == target)
              qDebug() << position;
      
          if (position == target)
              effect->setStrength(ACTIVATE);
          else
              effect->setStrength(DEACTIVATE);
      }
      
      

      When I run the program, then I get a lot of.

      QPainter::begin: A paint device can only be painted by one painter at a time.
      QPainter::translate: Painter not active
      

      As application output. These outputs seems to be related to the function call setGraphicsEffect(effect). If I remove that line, then of course nothing happens, but I also do not get these QPainter messages.

      What do you think I should do?

      J Offline
      J Offline
      Jakob Clausen
      wrote on last edited by
      #2

      @Jakob-Clausen Anyone?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Do you mean you have that effect once you start changing the effect strength ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • J Offline
          J Offline
          Jakob Clausen
          wrote on last edited by Jakob Clausen
          #4

          Not at first.
          This is the sequence of events:

          • call constructor
          • set stength to zero
          • setEffect on widget
          • change strength to larger than zero
            at the last point problems happen
          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jakob Clausen
            wrote on last edited by
            #5

            What does the error messages

            QPainter::begin: A paint device can only be painted by one painter at a time.
            QPainter::translate: Painter not active
            

            mean?

            jsulmJ 1 Reply Last reply
            0
            • J Jakob Clausen

              What does the error messages

              QPainter::begin: A paint device can only be painted by one painter at a time.
              QPainter::translate: Painter not active
              

              mean?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Jakob-Clausen Do you have more than one painter on same device?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              J 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Jakob-Clausen Do you have more than one painter on same device?

                J Offline
                J Offline
                Jakob Clausen
                wrote on last edited by
                #7

                @jsulm Good question. I was wondering the same thing. It looks like a painter is added, when I set the graphics effect. Is this true?
                The widget upon which the effect is set, is also added to a qstackedwidget. Could that cause the ... no more than one painter ... thing? If I add the effect to the qstackedwidget aka the parent, then this error also is no more.
                But it still does not look right.
                Do I need to repaint the widget?

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jakob Clausen
                  wrote on last edited by Jakob Clausen
                  #8

                  Something else is strange. Maybe a clue?
                  The navigation looks like it only has three buttons left. But all six of them are there. I can push them all, and the QWidgetStack changes accordingly. So the buttons are where they should be. But it looks like they are not.
                  And if I remove the effect, then I can make it all look well by calling repaint().

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jakob Clausen
                    wrote on last edited by
                    #9

                    Are there any limitations on the QGraphicsColorizeEffect?
                    Should it not be possible to just set it on any old widget?

                    jsulmJ 1 Reply Last reply
                    0
                    • J Jakob Clausen

                      Are there any limitations on the QGraphicsColorizeEffect?
                      Should it not be possible to just set it on any old widget?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #10

                      @Jakob-Clausen Do you paint manually on that widget (in paintEvent)?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        Jakob Clausen
                        wrote on last edited by
                        #11

                        No. I add subwidgets to a layout and thats it.

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          Jakob Clausen
                          wrote on last edited by
                          #12

                          I think I have found a way through it all. I can create a new widget of the same size and shape, and instead of a QGraphicsColorizeEffect I can use a QOpacityEffect and the move it to cover the navigationbar. But then the navigation wont accept touch events. Any around that?

                          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