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. Last empty column
Forum Updated to NodeBB v4.3 + New Features

Last empty column

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 454 Views 1 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.
  • QWorkingClassHeroQ Offline
    QWorkingClassHeroQ Offline
    QWorkingClassHero
    wrote on last edited by QWorkingClassHero
    #1

    In a QTableView I need the last (rightmost) column to be empty, expandable but not movable. The goal is that the table not to suddenly end (for I use alternate color for rows) or to ugly expand to the right. In QHeaderView there is a setFirstSectionMovable(bool).
    I need something similar for the last section, letting the rest of them movable. (in other words: Fill the rest of the table with an empty -not movable- column). Any clue how to acheive this ?

    Pl45m4P 1 Reply Last reply
    0
    • QWorkingClassHeroQ Offline
      QWorkingClassHeroQ Offline
      QWorkingClassHero
      wrote on last edited by QWorkingClassHero
      #4

      AMOQ:

      Be HeaderView a subclass of QHeaderView and have

      setSectionsMovable(true);
      setStretchLastSection(true);
      

      Treat the sectionMoved signal:

      connect(this, &QHeaderView::sectionMoved, [this](int, int, int newVisual) {                
      if(newVisual == count()-1) { moveSection(newVisual, newVisual-1); }
      });
      

      and override mousePressEvent:

      void HeaderView::mousePressEvent(QMouseEvent* event) {    
      int logicalIdx = logicalIndexAt(event->pos());       
      if(logicalIdx != count()-1) { QHeaderView::mousePressEvent(event); }
      }
      
      1 Reply Last reply
      0
      • QWorkingClassHeroQ QWorkingClassHero

        In a QTableView I need the last (rightmost) column to be empty, expandable but not movable. The goal is that the table not to suddenly end (for I use alternate color for rows) or to ugly expand to the right. In QHeaderView there is a setFirstSectionMovable(bool).
        I need something similar for the last section, letting the rest of them movable. (in other words: Fill the rest of the table with an empty -not movable- column). Any clue how to acheive this ?

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

        @QWorkingClassHero

        Subclass QTableView and do whatever you want to do with your last column.


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

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • QWorkingClassHeroQ Offline
          QWorkingClassHeroQ Offline
          QWorkingClassHero
          wrote on last edited by QWorkingClassHero
          #3

          I did override mousePressEvent() in a subclass of QHeaderView to skip (inactivate) the last section but it still can be moved by moving other column in its place and I don't know how to prevent this.

          1 Reply Last reply
          0
          • QWorkingClassHeroQ Offline
            QWorkingClassHeroQ Offline
            QWorkingClassHero
            wrote on last edited by QWorkingClassHero
            #4

            AMOQ:

            Be HeaderView a subclass of QHeaderView and have

            setSectionsMovable(true);
            setStretchLastSection(true);
            

            Treat the sectionMoved signal:

            connect(this, &QHeaderView::sectionMoved, [this](int, int, int newVisual) {                
            if(newVisual == count()-1) { moveSection(newVisual, newVisual-1); }
            });
            

            and override mousePressEvent:

            void HeaderView::mousePressEvent(QMouseEvent* event) {    
            int logicalIdx = logicalIndexAt(event->pos());       
            if(logicalIdx != count()-1) { QHeaderView::mousePressEvent(event); }
            }
            
            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