Important: Please read the Qt Code of Conduct -

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:


  • If that function not working because of some bug or smth, maybe there is another way to change color of a header?

  • I tried now even change stylesheet of whole TableWidget, and it worked, all table becomes grey. But not vertical and horizontal headers. WTF?

  • 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):

    alt text

    That lines between Headers and cells... Not good man, not good.

  • Okey. Is this possible to make desired horizontalHeaderItem invisible or something? Function ->hide(); would be perfect(so then total background will appear and goal is reached).

  • Not tested but you could subclass QHeaderView with something like:

    class SkipHeaderView : piblic QHeaderView{
    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();}
    void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const Q_DECL_OVERRIDE{
    QVector<int> m_sectionsToSkip;

Log in to reply