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. Why i can't change color of QString?
Qt 6.11 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 20.5k 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.
  • 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 Extensions
                      • Unsolved