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. [SOLVED] Shift QTableWidget cells after insert at top
QtWS25 Last Chance

[SOLVED] Shift QTableWidget cells after insert at top

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.5k 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.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    Hi,

    I am looking for the least CPU intensive way to do a QTableWidget insert at the first index while shifting all other table elements down.

    I currently have a side bar that contains a QTableWidget that contains a list of Custom QWidgets (all of the same class) that populates when specific 'user events' happen in the application. I basically created a custom QTableWidget cell.

    What I am looking to do is insert the newest 'user event' at the top of the list, and shift all of the other items down...Once there is 20 items in the list, I would like to remove the last item in the list, then proceed with inserting the newest 'user event' to the top of the list.

    The issue is that when I insert the widget into the table at row index 0, the other cell widgets to not get shifted.

    Is there another way to shift the widgets in the cells other than looping through every row and moving it one down?

    Here's how I am trying to do this right now, but I am just overwriting the cellWidget in row 0
    @
    // check the row count
    if (ui->table_events->rowCount() >= 20){
    // remove the last row of the table
    ui->table_events->removeCellWidget(ui->table_events->rowCount() - 1, 0);
    ui->table_events->removeRow(ui->table_events->rowCount() - 1);
    }

    // create the cell widget
    SystemEvent *event = new SystemEvent(this);
    
    // insert the event into the table
    ui->table_events->insertRow(0);
    ui->table_events->setCellWidget(0, 0, event);   // pass ownership
    ui->table_events->setRowHeight(0, event->height());
    
    // show event and do animation
    event->eventShow(title, description, icon, color, 0, 0);
    event->show();
    

    @

    Edit: There was actually nothing wrong with the existing code...I forgot to create column 0 so that the widgets would actually show... slaps forehead

    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