Why i can't change color of QString?
-
Hi
- i can't rly understand why it don't work with simple QStringListModel
Well @raven-worx was kind enough to show the source
so we can see how QStringListModel worksQVariant QStringListModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= lst.size()) return QVariant(); if (role == Qt::DisplayRole || role == Qt::EditRole) return lst.at(index.row()); return QVariant(); }The data function of a model IS the place where it returns the data for the roles so we can see
it only really uses (role == Qt::DisplayRole || role == Qt::EditRole) and
we want it to also use Qt::ForegroundRole. -
I made a proxy model to support roles in models that don't https://github.com/VSRonin/QtModelUtilities the class is called
RoleMaskProxyModel. Here is an example that uses it to colourQStringListModel: https://github.com/VSRonin/QtModelUtilities/blob/1.0.0/examples/exam_RoleMaskProxyModel/exam_rolemaskhighlight.cppHopefully I'll eventually find the time to complete adding that class to Qt: https://codereview.qt-project.org/#/c/245572/ -
I made a proxy model to support roles in models that don't https://github.com/VSRonin/QtModelUtilities the class is called
RoleMaskProxyModel. Here is an example that uses it to colourQStringListModel: https://github.com/VSRonin/QtModelUtilities/blob/1.0.0/examples/exam_RoleMaskProxyModel/exam_rolemaskhighlight.cppHopefully I'll eventually find the time to complete adding that class to Qt: https://codereview.qt-project.org/#/c/245572/@VRonin Looks very interesting.
I downloaded your rolemaskproxymodel and classes related to it(whole src directory), but when i tried to Run i got such strange stuff:
Oh and don't look at first two errors, they unrelated completelly, it appears when i swap compiler to Release mode, did'nt figure out what it is yet. -
If you just copy-paste the code you have to add
DEFINES += MODELUTILITIES_STATICto your .pro file -
Exact same answer.
There's a section in the readme that explains how to use the library: https://vsronin.github.io/QtModelUtilities/md__i_n_s_t_a_l_l.html -
Exact same answer.
There's a section in the readme that explains how to use the library: https://vsronin.github.io/QtModelUtilities/md__i_n_s_t_a_l_l.html -
You have to manually click on build-> rerun qmake every time you change something in the .pro file
-
yep!
AllDEFINES += MODELUTILITIES_STATICdoes is transformingMODELUTILITIES_EXPORTinto an empty string. if that doesn't work then just manually do a find and replace -
Actually, it probably just easier to replace the entire
modelutilities_global.hwith#ifndef modelutilities_global_h__ #define modelutilities_global_h__ #define MODELUTILITIES_EXPORT #endif // modelutilities_global_h__ -
@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 ?