Unsolved Why i can't change color of QString?
-
@VRonin Done. But still that four errors(
-
-
@SGaist said in Why i can't change color of QString?:
Did you build @VRonin library statically ?
@SGaist said in Why i can't change color of QString?:
Do you mean the symbol missing error ?
I tried multiple times: Build>Clean all>Run qmake>Rebuild all.
-
Do you have a .dll file matching that library ?
-
@SGaist What .dll? I just downloaded src folder, did'nt saw any dll in there
-
The .dll if you have built @VRonin's library.
Otherwise, how did you integrate it in your application ?
-
@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
-
@Engelard
Also the .cpp files , i hope ? -
@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 addinginclude(path/to/source/modelutilities.pri)
in your.pro
file. -
@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.
-
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);
-
@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:
-
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.
-
@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.
-
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(); }
-
@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?