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. QTableWidget: disabling automatic selection of row header when a column is selected and viceversa
Forum Updated to NodeBB v4.3 + New Features

QTableWidget: disabling automatic selection of row header when a column is selected and viceversa

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 3.6k 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.
  • B Offline
    B Offline
    Black Imp
    wrote on last edited by
    #4

    ok I 've found some solutions thou I have more problems

    disconnect(table->horizontalHeader(), SIGNAL(sectionPressed(int)),table, SLOT(selectColumn(int)));
    disconnect(table->verticalHeader(), SIGNAL(sectionPressed(int)),table, SLOT(selectRow(int)));
    

    then I reconnect to my slots which select no more than one row or column

    connect(table->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(onColumnSelected(int)));
    connect(table->verticalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(onRowSelected(int)));
    connect(table->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(onColumnDoubleClicked(int)));
    connect(table->verticalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(onRowDoubleClicked(int)));
    
    void MainWindow::onColumnSelected(int index)
    {
        qDebug() << __FUNCTION__ << "index " << index;
        table->selectColumn(index);
    
    }
    
    void MainWindow::onColumnDoubleClicked(int index)
    {
        qDebug() << __FUNCTION__ << "index " << index;
    }
    
    void MainWindow::onRowSelected(int index)
    {
        qDebug() << __FUNCTION__ << "index " << index;
        table->selectRow(index);
    }
    
    void MainWindow::onRowDoubleClicked(int index)
    {
        qDebug() << __FUNCTION__ << "index " << index;
    }
    
    void MainWindow::onCellSelected(int r, int c)
    {
        qDebug() << __FUNCTION__ << "row index " << r << " column index " << c;
    }
    
    void MainWindow::onCDoubleClicked(int row, int col)
    {
        qDebug() << __FUNCTION__ << "row index " << row << " column index " << col;
    }
    

    I didn't find a way to disconnect single cell pressed thou.

    JonBJ 1 Reply Last reply
    0
    • B Black Imp

      ok I 've found some solutions thou I have more problems

      disconnect(table->horizontalHeader(), SIGNAL(sectionPressed(int)),table, SLOT(selectColumn(int)));
      disconnect(table->verticalHeader(), SIGNAL(sectionPressed(int)),table, SLOT(selectRow(int)));
      

      then I reconnect to my slots which select no more than one row or column

      connect(table->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(onColumnSelected(int)));
      connect(table->verticalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(onRowSelected(int)));
      connect(table->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(onColumnDoubleClicked(int)));
      connect(table->verticalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(onRowDoubleClicked(int)));
      
      void MainWindow::onColumnSelected(int index)
      {
          qDebug() << __FUNCTION__ << "index " << index;
          table->selectColumn(index);
      
      }
      
      void MainWindow::onColumnDoubleClicked(int index)
      {
          qDebug() << __FUNCTION__ << "index " << index;
      }
      
      void MainWindow::onRowSelected(int index)
      {
          qDebug() << __FUNCTION__ << "index " << index;
          table->selectRow(index);
      }
      
      void MainWindow::onRowDoubleClicked(int index)
      {
          qDebug() << __FUNCTION__ << "index " << index;
      }
      
      void MainWindow::onCellSelected(int r, int c)
      {
          qDebug() << __FUNCTION__ << "row index " << r << " column index " << c;
      }
      
      void MainWindow::onCDoubleClicked(int row, int col)
      {
          qDebug() << __FUNCTION__ << "row index " << row << " column index " << col;
      }
      

      I didn't find a way to disconnect single cell pressed thou.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #5

      @Black-Imp
      There are signals like cellClicked & cellPressed, though I don't see you connecting those signals to your slots.

      What do you mean by/why do you want to "disconnect single cell pressed"? Signals are disconnected in the normal way, via QObject::disconnect(). The signal is for the table as a whole, so you can't connect/disconnect individual cells. However, in your slot you can handle only those you wish to. Though I suspect you already know that, so not sure what you have in mind.

      B 1 Reply Last reply
      0
      • JonBJ JonB

        @Black-Imp
        There are signals like cellClicked & cellPressed, though I don't see you connecting those signals to your slots.

        What do you mean by/why do you want to "disconnect single cell pressed"? Signals are disconnected in the normal way, via QObject::disconnect(). The signal is for the table as a whole, so you can't connect/disconnect individual cells. However, in your slot you can handle only those you wish to. Though I suspect you already know that, so not sure what you have in mind.

        B Offline
        B Offline
        Black Imp
        wrote on last edited by Black Imp
        #6

        @JonB I'd need to disconnect both headers and cells from any slot which automatically higlights them.

        My desired behaviour would be:

        i click on a cell, it highlights and it becomes selected.

        i click on a header section - row or column - and it highlights with all the cells on that row or on that column.

        I don't want more than a row/column selected, I don't want more than a single cell selected unless I selected a row or a column.

        I'm trying some solutions but I can't find a good compromised:

        1 . first of all, if I disconnect as I did header selectionPressed from selectColumn/Row I can't find a way to highlight programmatically a header section without selecting it.
        2. If I call, in my own slots connected to those signals , selectColumn(index); I get the good effect which only one row/column can be actually selected thou you can highlight more than one when you keep mouse button presse and move, but to have this behaviour you must keep table with a selection mode which allows for multiple selection. this means you cannot call setSelectionMode(QAbstractItemView::SingleSelection);
        3. If I don't call setSelectionMode(QAbstractItemView::SingleSelection); table allows for multiple cell selection by clicking on different cells. I only want multiple selection by clicking headers. I've tried all MultiSelection, ExtendedSelection, ContiguousSelection but none of them allow me to do what I need and user is able to make a mess like this:
        undesired multiple selection.png
        4. I could then try to disconnect some signal which automatically highlights cells when clicking over them and try to highlight them programmatically. I can't understand what slot I should disconnect and how to manually higlight cells.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Black Imp
          wrote on last edited by
          #7

          please you can close this thread. I've found a possible solution to my needs but I just have to solve a little last issue which I can't understand how to solve. I'd post a new thread with that question only, if possible

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @Black-Imp said in QTableWidget: disabling automatic selection of row header when a column is selected and viceversa:

            please you can close this thread

            Only you can do this - mark it as solved with the topic Tools.

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

            B 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @Black-Imp said in QTableWidget: disabling automatic selection of row header when a column is selected and viceversa:

              please you can close this thread

              Only you can do this - mark it as solved with the topic Tools.

              B Offline
              B Offline
              Black Imp
              wrote on last edited by
              #9

              @Christian-Ehrlicher ok thank you. I'll delete all and open a new one

              JonBJ 1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @Black-Imp said in QTableWidget: disabling automatic selection of row header when a column is selected and viceversa:

                I'll delete all and open a new one

                ?

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

                1 Reply Last reply
                0
                • B Black Imp

                  @Christian-Ehrlicher ok thank you. I'll delete all and open a new one

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #11

                  @Black-Imp
                  Please don't delete your topic, there is nothing wrong with your question and the discussions can always be useful to others reading it, even if you have found another approach now.

                  At the bottom of the page you should see a Topic Tools button (because this is your topic), pick Mark as Solved from there. If you choose to open a new topic now, you might like to put in a one-line reference to this topic from there so people know there was a relationship.

                  B 1 Reply Last reply
                  4
                  • JonBJ JonB

                    @Black-Imp
                    Please don't delete your topic, there is nothing wrong with your question and the discussions can always be useful to others reading it, even if you have found another approach now.

                    At the bottom of the page you should see a Topic Tools button (because this is your topic), pick Mark as Solved from there. If you choose to open a new topic now, you might like to put in a one-line reference to this topic from there so people know there was a relationship.

                    B Offline
                    B Offline
                    Black Imp
                    wrote on last edited by
                    #12

                    @JonB ok thou there's nothing solved here

                    jsulmJ 1 Reply Last reply
                    0
                    • B Black Imp

                      @JonB ok thou there's nothing solved here

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @Black-Imp You still have problems?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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