Impossible to setHorizontalHeader bg-color(QTableWidget)
-
I successfully changed so much stuff of my horisontalHeaderItems, but can't change it's colour, no error, program compiles and work but this two attempts have no effect:
ui->tabWidMain->horizontalHeaderItem(0)->setBackgroundColor(grey); ui->tabWidMain->model()->setHeaderData(0,Qt::Horizontal,QBrush(QColor("red")),Qt::BackgroundRole); -
This is a Windows-only "feature". The windows style ignores the background. You can test it by calling
QApplication::setStyle(QStyleFactory::create("Fusion"));and you'll see the background will work@VRonin said in Impossible to setHorizontalHeader bg-color(QTableWidget):
This is a Windows-only "feature".
Damn it! Spent about 2 hours to figure out what's wrong. iKnew i did nothing wrong!
Fusion is interesting. But i need windows style because it allow imitate thick, continues vertical lines between the columns(since there is no such functionality from Qt):

That lines between Headers and cells... Not good man, not good.
-
Not tested but you could subclass
QHeaderViewwith something like:class SkipHeaderView : piblic QHeaderView{ Q_OBJECT Q_DISABLE_COPY(SkipHeaderView) public: SkipHeaderView(Qt::Orientation orientation, QWidget *parent = Q_NULLPTR) :QHeaderView(orientation,parent ){} const QVector<int>& sectionsToSkip() const {return m_sectionsToSkip;} void setSectionsToSkip(const QVector<int>& sections){m_sectionsToSkip=sections; update();} protected: void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const Q_DECL_OVERRIDE{ if(!m_sectionsToSkip.contains(logicalIndex)) QHeaderView::paintSection(painter,rect,logicalIndex); } private: QVector<int> m_sectionsToSkip; };