Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Impossible to setHorizontalHeader bg-color(QTableWidget)

Impossible to setHorizontalHeader bg-color(QTableWidget)

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 994 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #1

    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);
    
    1 Reply Last reply
    0
    • EngelardE Offline
      EngelardE Offline
      Engelard
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • EngelardE Offline
        EngelardE Offline
        Engelard
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          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

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          EngelardE 1 Reply Last reply
          3
          • VRoninV VRonin

            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

            EngelardE Offline
            EngelardE Offline
            Engelard
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • EngelardE Offline
              EngelardE Offline
              Engelard
              wrote on last edited by
              #6

              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).

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #7

                Not tested but you could subclass QHeaderView with 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;
                };
                

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved