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 change mouse click behavior
Forum Updated to NodeBB v4.3 + New Features

QHeaderView change mouse click behavior

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.7k 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.
  • Q Offline
    Q Offline
    Qutie
    wrote on last edited by Qutie
    #1

    Hi everyone

    I have a table view with a QSortFilterProxyModel. The user can bind a column to QSortFilterProxyModel by Ctrl+Click the header. The column bound to the proxy model gets marked with an asterisks, but also the the sort behavior gets changed. How can I prevent the latter if the user "Ctrl+Clicks". The sort behavior should only be changed while no Ctrl-key is pressed.

    Do I have to subclass QHeaderview and reimplement mouse events?

    raven-worxR 1 Reply Last reply
    0
    • Q Qutie

      Hi everyone

      I have a table view with a QSortFilterProxyModel. The user can bind a column to QSortFilterProxyModel by Ctrl+Click the header. The column bound to the proxy model gets marked with an asterisks, but also the the sort behavior gets changed. How can I prevent the latter if the user "Ctrl+Clicks". The sort behavior should only be changed while no Ctrl-key is pressed.

      Do I have to subclass QHeaderview and reimplement mouse events?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Qutie said in QHeaderView change mouse click behavior:

      Do I have to subclass QHeaderview and reimplement mouse events?

      yes, exactly.
      Reimplement mousepress/mouserelease event handlers (alternatively install an event-filter) and simply don't call the base-class implementation in case CTRL is contained in the event.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        Qutie
        wrote on last edited by
        #3

        Thank's. After set my subclassed header view to TableView, the signal SectionPressed() was not fired. QTableView sets standard HeaderView SectionClickable to true. So I had to set it as well to true.

        MarkHeaderView::MarkHeaderView(Qt::Orientation orientation, QWidget *parent)
           :QHeaderView(orientation,parent)
        {
           setSectionsClickable(true);
           setHighlightSections(true);
        }
        
        void MarkHeaderView::mousePressEvent(QMouseEvent *e){
          if(QGuiApplication::queryKeyboardModifiers() != Qt::ControlModifier){
              QHeaderView::mousePressEvent(e);
           }
          else{
              emit SectionCtrlPressed(logicalIndexAt(e->pos()));
          }
        }
        
        1 Reply Last reply
        1

        • Login

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