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. How to insert a row at a specific location in QTable View and QTreeView
Forum Updated to NodeBB v4.3 + New Features

How to insert a row at a specific location in QTable View and QTreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 656 Views 1 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    Hi All
    I have QTablview Vie for example with 5 columns
    1 A F G H L
    2 A U J K P
    3 A U L I M
    4 A U L O P
    5 A T Y P Q

    I want to insert a row between 2 and 3 . Could you please let me know how to do that

    The new QTableView should be
    0 A B C D E
    1 A F G H L
    2 A U J K P
    3 A J L I N
    4 A U L I M
    5 A U L O P
    6 A T Y P Q

    1 Reply Last reply
    0
    • KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by KillerSmath
      #2

      You can use insertRow function to insert a new row before index 3 and use setItem to insert a new QStandardItem in each element of new row.

      >> Example:

      ... 
          model->insertRow(3);
          model->setItem(3, 0, new QStandardItem("A"));
          model->setItem(3, 1, new QStandardItem("J"));
          model->setItem(3, 2, new QStandardItem("L"));
          model->setItem(3, 3, new QStandardItem("I"));
          model->setItem(3, 4, new QStandardItem("N"));
      ...
      

      >> Read More:

      • QAbstractItemModel - insertRow documentation

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved