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. creating a selection range

creating a selection range

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

    Greetings.

    I have build a program in javascript that makes use of a QtDesigner UI with a few buttons and a QTableWidget.
    With that tablewidget I am capable of selecting items on the table and receiving the corresponding rows:

    Model = widgets["Obj_table"].selectionModel();
    Model.selectionChanged.connect(function () {
         vl_selected = Model.selectedRows();
        //Returns: QModelIndex(4,0,0x0,QTableModel(0xcb569b8)), QModelIndex(5,0,0x0,QTableModel(0xcb569b8)), for row 4 and 5
    }
    
    

    Though i am certain there is a inbuilt way to retrieve just the row numbers in QtDesigner, I have so far been unable to do it correctly, so I have opted to convert the resulting array items into strings and separating them until I have only the resulting numbers.

    This is not my actual problem, I'm just trying to give you a context.
    My problem comes now. Now I have the need to actually create a selection, not just receive one, and have the tablewidget alter the selection according to my commands.
    From what I've read on the documentation, I believe the function I need is this one: QModelIndex QAbstractItemModel::createIndex(int row, int column, void * ptr = 0) const, but my attempts so far have failed.

    Is is possible for someone to provide an example of how to make this work?

    Thank you very much.

    1 Reply Last reply
    0
    • Ghost_of_MagellanG Offline
      Ghost_of_MagellanG Offline
      Ghost_of_Magellan
      wrote on last edited by Ghost_of_Magellan
      #2

      Not exactly the answer to my question, but I managed to find an alternative.

      widgets["Obj_table"].setCurrentCell(Pos,0); //This isn't actually neccessary, but maintains selection in case you are doing something like passing values from one location of the table to the other. Otherwise the new selection will be considered AS WELL AS the latter current cell, thus making it possible for your selection to have more items than expected.
      //                                       1stRow, 1stColumn, LastRow, LastColumn
      var rangetable = new QTableWidgetSelectionRange(Pos, 0, Pos + RowRange-1, ColumnRangel-1);
      widgets["Obj_table"].setRangeSelected(rangetable, true);
      

      Thank you, nonetheless.

      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