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. having trouble with QTableWidgetSelectionRange?

having trouble with QTableWidgetSelectionRange?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 776 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.
  • M Offline
    M Offline
    manny
    wrote on last edited by
    #1

    hello,

    I have a question about QTableWidgetSelectionRange, mainly about what a selection range is (I know, really noob question). so is a selection range basically a range of all the cells from one point to another ie: topleft row of 3 to the bottom right column of 5, or does the range consist of the topleft row, and bottom right column of each and every single individual cell within the range, for example: cell [3, 4], cell[3, 5], etc.

    the reason why i am asking is because in a book i am reading called "c++ programming a gui with qt4 second edition" the author says that the selection will only consist of one cell, however the implemintation is desighned for multiple cells. here is the code:

        void Spreadsheet::copy()
       {
            QTableWidgetSelectionRange range = selectedRange();
            QString str;
    
          for(int i = 0; i < range.rowCount(); i++)
          {
                if(i > 0)
                {
                    str += "\n";
                }
    
                for(int j = 0; j < range.columnCount(); j++)
                {
                    if(j > 0)
                    {
                        str += "\t";
                    }
    
                  str += formula(range.topRow() + i, 
                                           range.leftColumn() + j);
                }
            }
            QApplication::clipboard()->setText(str);
        }
    

    selectedRange:

        QTableWidgetSelectionRange Spreadsheet::selectedRange() const
        {
            QList<QTableWidgetSelectionRange> ranges = selectedRanges();
            if(ranges.isEmpty())
            {
                return QTableWidgetSelectionRange();
            }
    
           return ranges.first();
        }
    

    the first function is desighned to iterate through all the rows of the range, implying there is more than one. however in the selectedRange() function, the author only returns range.first().

    any help is greatly appreciated

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Unless we are not reading the same paragraph, you misunderstood it. It says that there will be only one range not only one cell selected.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - 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