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. QHeaderView induvidual background colors
Forum Updated to NodeBB v4.3 + New Features

QHeaderView induvidual background colors

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 1.4k Views 2 Watching
  • 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.
  • Andy314A Andy314

    @JonB said in QHeaderView induvidual background colors:

    @Andy314

    class AdvHeaderView : public QHeaderView;
    

    You are finding that your derived AdvHeaderView is not producing any signals, is that right? Did you put Q_OBJECT macro in your declaration/definition of AdvHeaderView? Not sure, that may be required here?

    I seen that it produces no signals. Unfortunately Q_OBJECT wasn't the problem

    class AdvHeaderView : public QHeaderView
    {
        Q_OBJECT
    public:
        AdvHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr)
            : QHeaderView(orientation, parent) {}
    protected:
        void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override;
    }
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #10

    @Andy314

    • Temporarily replace your AdvHeaderView with a plain QHeaderView. Does the signal work?
    • Is it just the sectionClicked() signal which does not work or all signals do not work?
    • Make sure your headerClicked() has a qDebug() so we are sure it not getting called and/or try a lambda with just qDebug()in it as the slot.
    Andy314A 1 Reply Last reply
    0
    • JonBJ JonB

      @Andy314

      • Temporarily replace your AdvHeaderView with a plain QHeaderView. Does the signal work?
      • Is it just the sectionClicked() signal which does not work or all signals do not work?
      • Make sure your headerClicked() has a qDebug() so we are sure it not getting called and/or try a lambda with just qDebug()in it as the slot.
      Andy314A Offline
      Andy314A Offline
      Andy314
      wrote on last edited by
      #11

      @JonB said in QHeaderView induvidual background colors:

      @Andy314

      • Temporarily replace your AdvHeaderView with a plain QHeaderView. Does the signal work?
      • Is it just the sectionClicked() signal which does not work or all signals do not work?
      • Make sure your headerClicked() has a qDebug() so we are sure it not getting called and/or try a lambda with just qDebug()in it as the slot.

      If I reset the integrated HeaderView all works.
      I had integrated debug messages.

      Signal SectionResized and GeomtryChaged work always. All Mouse Enter/Click/DoubleClick etc. dont work.

      JonBJ 1 Reply Last reply
      1
      • Andy314A Andy314

        @JonB said in QHeaderView induvidual background colors:

        @Andy314

        • Temporarily replace your AdvHeaderView with a plain QHeaderView. Does the signal work?
        • Is it just the sectionClicked() signal which does not work or all signals do not work?
        • Make sure your headerClicked() has a qDebug() so we are sure it not getting called and/or try a lambda with just qDebug()in it as the slot.

        If I reset the integrated HeaderView all works.
        I had integrated debug messages.

        Signal SectionResized and GeomtryChaged work always. All Mouse Enter/Click/DoubleClick etc. dont work.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #12

        @Andy314
        On your AdvHeaderView instance what does bool QHeaderView::sectionsClickable() const return? Do you need to call void QHeaderView::setSectionsClickable(bool clickable) with true?

        Andy314A 1 Reply Last reply
        1
        • JonBJ JonB

          @Andy314
          On your AdvHeaderView instance what does bool QHeaderView::sectionsClickable() const return? Do you need to call void QHeaderView::setSectionsClickable(bool clickable) with true?

          Andy314A Offline
          Andy314A Offline
          Andy314
          wrote on last edited by
          #13

          @JonB said in QHeaderView induvidual background colors:

          @Andy314
          On your AdvHeaderView instance what does bool QHeaderView::sectionsClickable() const return? Do you need to call void QHeaderView::setSectionsClickable(bool clickable) with true?

          Yeh, that was the problem. Thank you for the tip.

          JonBJ 1 Reply Last reply
          0
          • Andy314A Andy314

            @JonB said in QHeaderView induvidual background colors:

            @Andy314
            On your AdvHeaderView instance what does bool QHeaderView::sectionsClickable() const return? Do you need to call void QHeaderView::setSectionsClickable(bool clickable) with true?

            Yeh, that was the problem. Thank you for the tip.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #14

            @Andy314
            What I do not know is why/how a derived QHeaderView does not get this set as a base QHeaderView does. Perhaps a Qt/C++ expert would care to enlighten us?

            Pl45m4P Andy314A 2 Replies Last reply
            0
            • JonBJ JonB

              @Andy314
              What I do not know is why/how a derived QHeaderView does not get this set as a base QHeaderView does. Perhaps a Qt/C++ expert would care to enlighten us?

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #15

              @JonB said in QHeaderView induvidual background colors:

              as a base QHeaderView does.

              Are you sure about that? Haven't checked the code but this from the documentation

              Returns true if the header is clickable; otherwise returns false. A clickable header could be set up to allow the user to change the representation of the data in the view related to the header.

              sounds like it's not the default in QHeaderView


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              JonBJ 1 Reply Last reply
              0
              • Pl45m4P Pl45m4

                @JonB said in QHeaderView induvidual background colors:

                as a base QHeaderView does.

                Are you sure about that? Haven't checked the code but this from the documentation

                Returns true if the header is clickable; otherwise returns false. A clickable header could be set up to allow the user to change the representation of the data in the view related to the header.

                sounds like it's not the default in QHeaderView

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #16

                @Pl45m4

                Are you sure about that?

                No, I am not sure. I am relying on the OP's statement that with a non-subclassed QHeaderView in his QTableView clicking works (by default) while as soon as he sub-classes to shown AdvHeaderView it does not work. And wondering how that would be.

                Christian EhrlicherC 1 Reply Last reply
                0
                • JonBJ JonB

                  @Pl45m4

                  Are you sure about that?

                  No, I am not sure. I am relying on the OP's statement that with a non-subclassed QHeaderView in his QTableView clicking works (by default) while as soon as he sub-classes to shown AdvHeaderView it does not work. And wondering how that would be.

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #17

                  @JonB said in QHeaderView induvidual background colors:

                  And wondering how that would be.

                  It was enabled in the ui but since the header gets replaced in c++ it was overridden.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  JonBJ 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @JonB said in QHeaderView induvidual background colors:

                    And wondering how that would be.

                    It was enabled in the ui but since the header gets replaced in c++ it was overridden.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #18

                    @Christian-Ehrlicher said in QHeaderView induvidual background colors:

                    It was enabled in the ui but since the header gets replaced in c++ it was overridden.

                    Ah, no wonder, at least that makes sense!

                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Andy314
                      What I do not know is why/how a derived QHeaderView does not get this set as a base QHeaderView does. Perhaps a Qt/C++ expert would care to enlighten us?

                      Andy314A Offline
                      Andy314A Offline
                      Andy314
                      wrote on last edited by Andy314
                      #19

                      @JonB said in QHeaderView induvidual background colors:

                      @Andy314
                      What I do not know is why/how a derived QHeaderView does not get this set as a base QHeaderView does. Perhaps a Qt/C++ expert would care to enlighten us?

                      That is exact the problem I struggled.
                      From the logic it can only be that the QTableView itself configures its QHeaderView correct.
                      Indeed I found the code for it:

                      void QTableViewPrivate::init()
                      {
                          Q_Q(QTableView);
                          q->setEditTriggers(editTriggers|QAbstractItemView::AnyKeyPressed);
                          QHeaderView *vertical = new QHeaderView(Qt::Vertical, q);
                          vertical->setSectionsClickable(true);
                          vertical->setHighlightSections(true);
                          q->setVerticalHeader(vertical);
                          QHeaderView *horizontal = new QHeaderView(Qt::Horizontal, q);
                          horizontal->setSectionsClickable(true);  // Here is the code ****************************
                          horizontal->setHighlightSections(true);
                          q->setHorizontalHeader(horizontal);
                          tabKeyNavigation = true;
                      #if QT_CONFIG(abstractbutton)
                          cornerWidget = new QTableCornerButton(q);
                          cornerWidget->setFocusPolicy(Qt::NoFocus);
                          QObject::connect(cornerWidget, SIGNAL(clicked()), 
                      q, SLOT(selectAll()));
                      #endif
                      }
                      
                      1 Reply Last reply
                      0
                      • Andy314A Andy314 has marked this topic as solved on

                      • Login

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