Solved Qtableview set background color to some columns
-
@VRonin Thanks
-
if just to color one column and no validation on input in column then that done using Qt::BackgroundRole either via setData so need to refer which class QAbstractitem
-
class BackgroundBrushDelegate : public QStyledItemDelegate{ Q_OBJECT Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush NOTIFY backgroundBrushChanged) Q_DISABLE_COPY(BackgroundBrushDelegate) public: explicit BackgroundBrushDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {} BackgroundBrushDelegate(const QBrush& brush, QObject *parent = nullptr) : QStyledItemDelegate(parent) , m_backgroundBrush(brush) {} const QBrush& backgroundBrush() const { return m_backgroundBrush; } void setBackgroundBrush(const QBrush& brush) { if(m_backgroundBrush==brush) return; m_backgroundBrush=brush; backgroundBrushChanged(m_backgroundBrush); } signals: void backgroundBrushChanged(const QBrush& brush); protected: void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override { QStyledItemDelegate::initStyleOption(option,index); option->backgroundBrush = m_backgroundBrush; } private: QBrush m_backgroundBrush; }
when i am using this code
after applying brushdelegate in that column i am not able to type other then integer can you plz help me how to do ? -
Please help
stuck for some assignment
Thankyou -
@n-2204 said in Qtableview set background color to some columns:
after applying brushdelegate in that column i am not able to type other then integer can you plz help me how to do ?
This does not sound like a brush delegate issue. Earlier you have in
createEditor()
:editor->setValidator(new QIntValidator);
Make sure that is applying to the column (look at
index
parameter) where you want an integer, not some other column, at a guess? -
@n-2204 said in Qtableview set background color to some columns:
stuck for some assignment
I'll quote the wise @mrjj
the teacher will catch it and fail them if too much code is just copied.
We gave you 2 possible solutions, one with and one without validator. We even integrated it in your existing code. What more can we do to help?
-
Thanks all for you help
May be i asked more that is easy for you ,but as i am new to c++ and qt, so i am not aware of all the concepts.
so for me its little tough in implementation -
This post is deleted! -
@VRonin Hi! I am trying to do something similar; however, I am building an application in python, not C++. Could you help me how to understand this code better so I can convert it to python? Or could you maybe show me how it would be in python?
-
@Chuck333 What is your exact problem/question?