Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why i can't change color of QString?
Qt 6.12 LTS is out! See what's new in the release blog

Why i can't change color of QString?

Scheduled Pinned Locked Moved Unsolved General and Desktop
46 Posts 7 Posters 41.4k 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.
  • VRoninV VRonin

    yep!
    All DEFINES += MODELUTILITIES_STATIC does is transforming MODELUTILITIES_EXPORT into an empty string. if that doesn't work then just manually do a find and replace

    EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by
    #29

    @VRonin oKay. In what files that stuff which i should to replace? I only can assume that such stuff MODELUTILITIES_EXPORT is macro, so it must be in some .h files, right?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #30

      Actually, it probably just easier to replace the entire modelutilities_global.h with

      #ifndef modelutilities_global_h__
      #define modelutilities_global_h__
      #define MODELUTILITIES_EXPORT
      #endif // modelutilities_global_h__
      

      "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

      EngelardE 1 Reply Last reply
      0
      • VRoninV VRonin

        Actually, it probably just easier to replace the entire modelutilities_global.h with

        #ifndef modelutilities_global_h__
        #define modelutilities_global_h__
        #define MODELUTILITIES_EXPORT
        #endif // modelutilities_global_h__
        
        EngelardE Offline
        EngelardE Offline
        Engelard
        wrote on last edited by
        #31

        @VRonin Done. But still that four errors(

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

          Hi,

          Do you mean the symbol missing error ?

          Did you build @VRonin library statically ?

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

          EngelardE 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Do you mean the symbol missing error ?

            Did you build @VRonin library statically ?

            EngelardE Offline
            EngelardE Offline
            Engelard
            wrote on last edited by
            #33

            @SGaist said in Why i can't change color of QString?:

            Did you build @VRonin library statically ?

            0_1553942357112_statt.jpg

            @SGaist said in Why i can't change color of QString?:

            Do you mean the symbol missing error ?

            0_1553942408999_errr.jpg

            I tried multiple times: Build>Clean all>Run qmake>Rebuild all.

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

              Do you have a .dll file matching that library ?

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

              EngelardE 1 Reply Last reply
              0
              • SGaistS SGaist

                Do you have a .dll file matching that library ?

                EngelardE Offline
                EngelardE Offline
                Engelard
                wrote on last edited by
                #35

                @SGaist What .dll? I just downloaded src folder, did'nt saw any dll in there

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

                  The .dll if you have built @VRonin's library.

                  Otherwise, how did you integrate it in your application ?

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

                  EngelardE 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    The .dll if you have built @VRonin's library.

                    Otherwise, how did you integrate it in your application ?

                    EngelardE Offline
                    EngelardE Offline
                    Engelard
                    wrote on last edited by
                    #37

                    @SGaist said in Why i can't change color of QString?:

                    Otherwise, how did you integrate it in your application ?

                    Just included rolemaskproxymodel.h and start using that stuff what he showed in example

                    mrjjM VRoninV 2 Replies Last reply
                    0
                    • EngelardE Engelard

                      @SGaist said in Why i can't change color of QString?:

                      Otherwise, how did you integrate it in your application ?

                      Just included rolemaskproxymodel.h and start using that stuff what he showed in example

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

                      @Engelard
                      Also the .cpp files , i hope ?

                      1 Reply Last reply
                      1
                      • EngelardE Engelard

                        @SGaist said in Why i can't change color of QString?:

                        Otherwise, how did you integrate it in your application ?

                        Just included rolemaskproxymodel.h and start using that stuff what he showed in example

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

                        @Engelard said in Why i can't change color of QString?:

                        Just included rolemaskproxymodel.h and start using that stuff what he showed in example

                        @VRonin said in Why i can't change color of QString?:

                        There's a section in the readme that explains how to use the library: https://github.com/VSRonin/QtModelUtilities/tree/dev#installation

                        And it states:

                        if you use qmake (Qt Creator), you can include the entire source of the library directly in your code by adding include(path/to/source/modelutilities.pri) in your .pro file.

                        "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

                        EngelardE 1 Reply Last reply
                        2
                        • VRoninV VRonin

                          @Engelard said in Why i can't change color of QString?:

                          Just included rolemaskproxymodel.h and start using that stuff what he showed in example

                          @VRonin said in Why i can't change color of QString?:

                          There's a section in the readme that explains how to use the library: https://github.com/VSRonin/QtModelUtilities/tree/dev#installation

                          And it states:

                          if you use qmake (Qt Creator), you can include the entire source of the library directly in your code by adding include(path/to/source/modelutilities.pri) in your .pro file.

                          EngelardE Offline
                          EngelardE Offline
                          Engelard
                          wrote on last edited by
                          #40

                          @VRonin Done. It compiles. But it seems like proxyModel eventually empty. tempBx - is pointer to existed ComboBox:

                          QStringListModel *tempStrMod = new QStringListModel(personalList);
                          RoleMaskProxyModel proxyModel;
                          proxyModel.setSourceModel(tempStrMod);
                          tempBx->setModel(&proxyModel);
                          

                          But if i'd change ->setModel to tempStrMod it works.

                          1 Reply Last reply
                          0
                          • VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on last edited by
                            #41

                            You are creating the proxy model on the stack. it is most likely going out of scope.

                            QStringListModel *tempStrMod = new QStringListModel(personalList);
                            RoleMaskProxyModel* proxyModel =new RoleMaskProxyModel(personalList);
                            proxyModel->setSourceModel(tempStrMod);
                            tempBx->setModel(proxyModel);
                            

                            "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

                            EngelardE 1 Reply Last reply
                            4
                            • VRoninV VRonin

                              You are creating the proxy model on the stack. it is most likely going out of scope.

                              QStringListModel *tempStrMod = new QStringListModel(personalList);
                              RoleMaskProxyModel* proxyModel =new RoleMaskProxyModel(personalList);
                              proxyModel->setSourceModel(tempStrMod);
                              tempBx->setModel(proxyModel);
                              
                              EngelardE Offline
                              EngelardE Offline
                              Engelard
                              wrote on last edited by
                              #42

                              @VRonin Yep. Btw in constructor should be placed temporyStringListModel, what i did. And it does'nt change color of ComboBox mainWidget, only in list(as before with that example where was QStandaradItem), and after like... third use of my function(which create that proxy model), it crashed with that window:

                              0_1554220631396_565656.jpg

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

                                Hi,

                                Why are you re-creating your models every time ?

                                You could just update the content of the QStringListModel rather that recreate everything each time.

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

                                EngelardE 1 Reply Last reply
                                1
                                • SGaistS SGaist

                                  Hi,

                                  Why are you re-creating your models every time ?

                                  You could just update the content of the QStringListModel rather that recreate everything each time.

                                  EngelardE Offline
                                  EngelardE Offline
                                  Engelard
                                  wrote on last edited by Engelard
                                  #44

                                  @SGaist replaced all to the constructor. Nothing changed. I understand that @VRonin libraries should grant the possibility to have any Roles on any kind of objects. That's nice feature, will use it in some future maybe. But problem of this topic( i just now realised) - that Qt itself can not change colors of a text of ComboBoxes. Yet.

                                  1 Reply Last reply
                                  0
                                  • VRoninV Offline
                                    VRoninV Offline
                                    VRonin
                                    wrote on last edited by
                                    #45

                                    I tried and it works for me:

                                    #include <QApplication>
                                    #include <QStringListModel>
                                    #include <rolemaskproxymodel.h>
                                    #include <QComboBox>
                                    #include <QBrush>
                                    int main(int argc, char ** argv)
                                    {
                                        QApplication app(argc,argv);
                                        QComboBox mainCombo;
                                        QStringListModel baseModel(QStringList{"test","test1","tes2"});
                                        RoleMaskProxyModel proxy;
                                        proxy.setSourceModel(&baseModel);
                                        proxy.addMaskedRole(Qt::ForegroundRole);
                                        proxy.setData(proxy.index(1,0),QBrush(Qt::red),Qt::ForegroundRole);
                                        mainCombo.setModel(&proxy);
                                        mainCombo.show();
                                        return app.exec();
                                    }
                                    
                                    

                                    "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

                                    EngelardE 1 Reply Last reply
                                    1
                                    • VRoninV VRonin

                                      I tried and it works for me:

                                      #include <QApplication>
                                      #include <QStringListModel>
                                      #include <rolemaskproxymodel.h>
                                      #include <QComboBox>
                                      #include <QBrush>
                                      int main(int argc, char ** argv)
                                      {
                                          QApplication app(argc,argv);
                                          QComboBox mainCombo;
                                          QStringListModel baseModel(QStringList{"test","test1","tes2"});
                                          RoleMaskProxyModel proxy;
                                          proxy.setSourceModel(&baseModel);
                                          proxy.addMaskedRole(Qt::ForegroundRole);
                                          proxy.setData(proxy.index(1,0),QBrush(Qt::red),Qt::ForegroundRole);
                                          mainCombo.setModel(&proxy);
                                          mainCombo.show();
                                          return app.exec();
                                      }
                                      
                                      
                                      EngelardE Offline
                                      EngelardE Offline
                                      Engelard
                                      wrote on last edited by
                                      #46

                                      @VRonin The only difference is that you don't use constructor when creating proxy model and your all stuff is in one function. Are you sure that your text in ComboBox when closed, is colored?

                                      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
                                      • Unsolved