creating a selection range



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.