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. Dificulties with selectionModel and selectedRows in qtablewidget.

Dificulties with selectionModel and selectedRows in qtablewidget.

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 676 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 am attempting to make a small script for QCad (computer aided drafting software) using QtDesigner to build the UI but I am having dificulties in understanding the libraries and examples in Qt sites and applying them.
    One possibility that justifies my difficulty may be the fact that I am using Javascript and the vast majority of examples being given on c++.

    Currently I have a table with data called "Obj_table" and the following code:
    appWin.handleUserMessage("Button entered fine");
    var rowlist0 = widgets["Obj_table"].selectionModel();
    appWin.handleUserMessage("select model has been declared");
    var rowlist1 = rowlist0.selectedRows();
    appWin.handleUserMessage("rowlist has been declared");
    appWin.handleUserMessage(rowlist1.toString());

    appWin.handleUserMessage inserts a message into the command line of QCad, so I can see where I bummed out on the code.
    The code runs successfully, but what is returned in rowlist1 comes in this format:

    QModelIndex(10,0,0x0,QTableModel(0x8606360) ) ,QModelIndex(8,0,0x0,QTableModel(0x8606360) ) ,QModelIndex(5,0,0x0,QTableModel(0x8606360) ) ,QModelIndex(2,0,0x0,QTableModel(0x8606360) )

    Where the 10, 8, 5 and 2 correspond to the rows I had selected on my widget (apparently it even registers them in the order I selected them on the table). So technically, it DOES give me the rows I asked for.

    So I ask: Have I skipped an important step that would have given me the direct result (10, 8, 5, 2) without the added extras or is this what I was supposed to return from the function and additional code to filter and convert the result was expected from the get go?
    Honestly, I think I messed up somewhere or misunderstood the way the class is supposed to operate.

    I would apreciate a correction and explanation, if possible.

    Thank you very much.

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

      Hi and welcome to devnet,

      From what I can see, if you want only the row number you selected, you'll have to build a list looping through rowList1 and ask for the row..

      selectedRows works as expected since it returns the list of index matching the rows you 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
      1
      • Ghost_of_MagellanG Offline
        Ghost_of_MagellanG Offline
        Ghost_of_Magellan
        wrote on last edited by
        #3

        Thank you for the welcoming and for the answer.

        Best regards.

        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