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. QColor("red") is drawn as blue ?
Forum Updated to NodeBB v4.3 + New Features

QColor("red") is drawn as blue ?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 821 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I am using a Qt 4.8 and QMap to store colours:

    typedef QMap<QString, QColor> tFaultsMap;
    

    In my class:

    private:
        tFaultsMap mmpFaults;
    

    Inserting an entry into the map:

    mmpFaults.insert(strTabKey, QColor("red"));
    

    When the tab is painted I can see that the tab is draw with a blue background not red, I have encountered this before where the red and blue components are swapped around, how can I fix this?

    This is running on a version of Linux developed inhouse, this issue seems only apparent when getting retrieving the colour from the map.

    Kind Regards,
    Sy

    JonBJ 1 Reply Last reply
    0
    • JonBJ JonB

      @SPlatten
      It seems extremely unlikely that QColor("red") could return the red color normally but miraculously return the blue color when stored in or retrieved from a QMap. Unless you can find a bug report to that effect (which I doubt) I would look elsewhere for your issue (e.g. maybe you overwrite that key entry's value later, or it's not used correctly on the tab and that defaults to blue). You could also try with QColor(Qt::red). It's easy enough for you to set this up in a test case, and of course remove the "tab drawing" from the equation....

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by SPlatten
      #3

      @JonB , it is an apparent bug in Qt, probably just this version of Qt, I have now fixed it by swapping around red and blue. When the QColor is created by passing "red", all is good and the name returns #ff000.

      The problem comes when storing the colour in the QMap when extracting it from the map, the name then returns #0000ff.

      I've fixed this by doing the following after taking the colour from the map:

      QColor color(citFound->value());
      const int cintBlue(color.blue());
      const int cintRed(color.red());
      color.setBlue(cintRed);
      color.setRed(cintBlue);
      

      The displayed colour is now correct and name returns #ff0000.

      Kind Regards,
      Sy

      VRoninV JonBJ 2 Replies Last reply
      0
      • SPlattenS SPlatten

        I am using a Qt 4.8 and QMap to store colours:

        typedef QMap<QString, QColor> tFaultsMap;
        

        In my class:

        private:
            tFaultsMap mmpFaults;
        

        Inserting an entry into the map:

        mmpFaults.insert(strTabKey, QColor("red"));
        

        When the tab is painted I can see that the tab is draw with a blue background not red, I have encountered this before where the red and blue components are swapped around, how can I fix this?

        This is running on a version of Linux developed inhouse, this issue seems only apparent when getting retrieving the colour from the map.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @SPlatten
        It seems extremely unlikely that QColor("red") could return the red color normally but miraculously return the blue color when stored in or retrieved from a QMap. Unless you can find a bug report to that effect (which I doubt) I would look elsewhere for your issue (e.g. maybe you overwrite that key entry's value later, or it's not used correctly on the tab and that defaults to blue). You could also try with QColor(Qt::red). It's easy enough for you to set this up in a test case, and of course remove the "tab drawing" from the equation....

        SPlattenS 1 Reply Last reply
        0
        • JonBJ JonB

          @SPlatten
          It seems extremely unlikely that QColor("red") could return the red color normally but miraculously return the blue color when stored in or retrieved from a QMap. Unless you can find a bug report to that effect (which I doubt) I would look elsewhere for your issue (e.g. maybe you overwrite that key entry's value later, or it's not used correctly on the tab and that defaults to blue). You could also try with QColor(Qt::red). It's easy enough for you to set this up in a test case, and of course remove the "tab drawing" from the equation....

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by SPlatten
          #3

          @JonB , it is an apparent bug in Qt, probably just this version of Qt, I have now fixed it by swapping around red and blue. When the QColor is created by passing "red", all is good and the name returns #ff000.

          The problem comes when storing the colour in the QMap when extracting it from the map, the name then returns #0000ff.

          I've fixed this by doing the following after taking the colour from the map:

          QColor color(citFound->value());
          const int cintBlue(color.blue());
          const int cintRed(color.red());
          color.setBlue(cintRed);
          color.setRed(cintBlue);
          

          The displayed colour is now correct and name returns #ff0000.

          Kind Regards,
          Sy

          VRoninV JonBJ 2 Replies Last reply
          0
          • SPlattenS SPlatten

            @JonB , it is an apparent bug in Qt, probably just this version of Qt, I have now fixed it by swapping around red and blue. When the QColor is created by passing "red", all is good and the name returns #ff000.

            The problem comes when storing the colour in the QMap when extracting it from the map, the name then returns #0000ff.

            I've fixed this by doing the following after taking the colour from the map:

            QColor color(citFound->value());
            const int cintBlue(color.blue());
            const int cintRed(color.red());
            color.setBlue(cintRed);
            color.setRed(cintBlue);
            

            The displayed colour is now correct and name returns #ff0000.

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #4

            @SPlatten said in QColor("red") is drawn as blue ?:

            The problem comes when storing the colour in the QMap when extracting it from the map

            It can't be. it just can't

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            SPlattenS 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @JonB , it is an apparent bug in Qt, probably just this version of Qt, I have now fixed it by swapping around red and blue. When the QColor is created by passing "red", all is good and the name returns #ff000.

              The problem comes when storing the colour in the QMap when extracting it from the map, the name then returns #0000ff.

              I've fixed this by doing the following after taking the colour from the map:

              QColor color(citFound->value());
              const int cintBlue(color.blue());
              const int cintRed(color.red());
              color.setBlue(cintRed);
              color.setRed(cintBlue);
              

              The displayed colour is now correct and name returns #ff0000.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #5

              @SPlatten
              So far as I know QMap does not have any particular code for a QColor as the value, it's just a templated for a generic T. So you are saying:

              QColor c = QColor("red");
              qDebug() << c;
              

              works, but

              QColor c = QColor("red");
              qDebug() << c;
              map.insert("red", c);
              qDebug() << map["red"];
              

              shows a different value for the two qDebug()s, right?

              Maybe QMap is broken in 4.8, nobody else noticed but you'd better remove all QMaps from your code if it's broken like that it's too dangerous to use.

              SPlattenS 1 Reply Last reply
              0
              • JonBJ JonB

                @SPlatten
                So far as I know QMap does not have any particular code for a QColor as the value, it's just a templated for a generic T. So you are saying:

                QColor c = QColor("red");
                qDebug() << c;
                

                works, but

                QColor c = QColor("red");
                qDebug() << c;
                map.insert("red", c);
                qDebug() << map["red"];
                

                shows a different value for the two qDebug()s, right?

                Maybe QMap is broken in 4.8, nobody else noticed but you'd better remove all QMaps from your code if it's broken like that it's too dangerous to use.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #6

                @JonB , sorry, I haven't got the time right now to try your code, but what I posted in my last post is exactly what I've observed. After googling this issue before trying to fix it, its not new, others have reported it before, I don't expect this is a problem in later releases of Qt, probably just a but in the 4.8 release?

                Kind Regards,
                Sy

                JonBJ 1 Reply Last reply
                0
                • VRoninV VRonin

                  @SPlatten said in QColor("red") is drawn as blue ?:

                  The problem comes when storing the colour in the QMap when extracting it from the map

                  It can't be. it just can't

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by SPlatten
                  #7

                  @VRonin , try it with 4.8, I wouldn't expect it to be an issue in current releases. Its a big endian / little endian problem, so its also OS / hardware dependant.

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0
                  • SPlattenS SPlatten

                    @JonB , sorry, I haven't got the time right now to try your code, but what I posted in my last post is exactly what I've observed. After googling this issue before trying to fix it, its not new, others have reported it before, I don't expect this is a problem in later releases of Qt, probably just a but in the 4.8 release?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #8

                    @SPlatten said in QColor("red") is drawn as blue ?:

                    After googling this issue before trying to fix it, its not new, others have reported it before

                    Got it. I tried Googling qt4 qmap qcolor but got nothing relevant. Could you just provide a link to whatever else has the same problem, will only take you a second, thanks.

                    SPlattenS 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @SPlatten said in QColor("red") is drawn as blue ?:

                      After googling this issue before trying to fix it, its not new, others have reported it before

                      Got it. I tried Googling qt4 qmap qcolor but got nothing relevant. Could you just provide a link to whatever else has the same problem, will only take you a second, thanks.

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #9

                      @JonB , try this:
                      https://www.google.co.uk/search?q=qt+red+and+blue+swapped&ei=4Hm9YvjzJ_WgptQPkJG3qA8&ved=0ahUKEwj449Dn-tT4AhV1kIkEHZDIDfUQ4dUDCBk&uact=5&oq=qt+red+and+blue+swapped&gs_lcp=Cgdnd3Mtd2l6EAMyBQghEKABMgUIIRCgATIFCCEQoAE6BwgAEEcQsAM6BQgAEJECOgQIABBDOgQILhBDOgUIABCABDoFCAAQkgM6BwgAELEDEEM6CAgAEIAEELEDOgcIABDJAxBDOgYIABAeEBY6CQgAEB4QyQMQFjoICAAQHhAWEAo6BwghEAoQoAE6BAghEBU6CAghEB4QFhAdOgoIIRAeEA8QFhAdSgQIQRgASgQIRhgAUNgQWIc1YKw2aAJwAHgAgAHWAYgBphSSAQcxMC4xMi4xmAEAoAEByAEIwAEB&sclient=gws-wiz&safe=active&ssui=on

                      Kind Regards,
                      Sy

                      JonBJ 2 Replies Last reply
                      1
                      • SPlattenS SPlatten

                        @JonB , try this:
                        https://www.google.co.uk/search?q=qt+red+and+blue+swapped&ei=4Hm9YvjzJ_WgptQPkJG3qA8&ved=0ahUKEwj449Dn-tT4AhV1kIkEHZDIDfUQ4dUDCBk&uact=5&oq=qt+red+and+blue+swapped&gs_lcp=Cgdnd3Mtd2l6EAMyBQghEKABMgUIIRCgATIFCCEQoAE6BwgAEEcQsAM6BQgAEJECOgQIABBDOgQILhBDOgUIABCABDoFCAAQkgM6BwgAELEDEEM6CAgAEIAEELEDOgcIABDJAxBDOgYIABAeEBY6CQgAEB4QyQMQFjoICAAQHhAWEAo6BwghEAoQoAE6BAghEBU6CAghEB4QFhAdOgoIIRAeEA8QFhAdSgQIQRgASgQIRhgAUNgQWIc1YKw2aAJwAHgAgAHWAYgBphSSAQcxMC4xMi4xmAEAoAEByAEIwAEB&sclient=gws-wiz&safe=active&ssui=on

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #10

                        @SPlatten
                        Thanks. Nothing from that mentions QMap anywhere, more device/driver-specific stuff. But have to respect your finding! Very, very odd that QMap could be at issue even if there is indeed a red/blue problem in some circumstances.

                        It's not possible that your issue is a driver or whatever, where you have to do the swap, but not actually related to QMap?

                        1 Reply Last reply
                        0
                        • SPlattenS SPlatten

                          @JonB , try this:
                          https://www.google.co.uk/search?q=qt+red+and+blue+swapped&ei=4Hm9YvjzJ_WgptQPkJG3qA8&ved=0ahUKEwj449Dn-tT4AhV1kIkEHZDIDfUQ4dUDCBk&uact=5&oq=qt+red+and+blue+swapped&gs_lcp=Cgdnd3Mtd2l6EAMyBQghEKABMgUIIRCgATIFCCEQoAE6BwgAEEcQsAM6BQgAEJECOgQIABBDOgQILhBDOgUIABCABDoFCAAQkgM6BwgAELEDEEM6CAgAEIAEELEDOgcIABDJAxBDOgYIABAeEBY6CQgAEB4QyQMQFjoICAAQHhAWEAo6BwghEAoQoAE6BAghEBU6CAghEB4QFhAdOgoIIRAeEA8QFhAdSgQIQRgASgQIRhgAUNgQWIc1YKw2aAJwAHgAgAHWAYgBphSSAQcxMC4xMi4xmAEAoAEByAEIwAEB&sclient=gws-wiz&safe=active&ssui=on

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #11

                          @SPlatten
                          I thought about this. The only thing QMap should be doing is using the QColor copy constructor to store the value (correct me if I'm wrong). Which would imply that has got it wrong. Which ought to mean (I believe)

                          QColor("red") != QColor(QColor("red"))
                          

                          ? In which case be very careful about copying colors anywhere?!

                          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