Forum
Sign Up
× DataGrid for Qt.C++

add a new row in grid

4 years 4 months ago #1 by jia
add a new row in grid was created by jia
Hello,
I want to add a new row in grid and show them after added.
my code like these
int xSimGridCtrl::addRow()
{
	//bool inc = m_model->insertRow(0);

	Qtitan::GridTableView* view = this->view<Qtitan::GridTableView>();	
	view->beginUpdate();
	int modelRowIndex = 0;// view->modelController()->model()->rowCount();
	view->modelController()->beginAddRow(modelRowIndex); // To be here to value does not be catched by the filter.
	bool suc = view->modelController()->insertModelRow(modelRowIndex);
	view->modelController()->endAddRow();	
	int rowIndex = view->modelController()->ensureVisible(modelRowIndex);
	view->endUpdate();
	view->requestUpdateLayout();
	this->update();
	return rowIndex;
}

The new row didn't show immediately . It can be show after I click column for sorting.

Please Log in or Create an account to join the conversation.

More
4 years 4 months ago #2 by Developer Machines
It is not a good idea to use low-level grid API to add the row. You can add the row directly to the model and then scroll to it.
    GridTableView* view = m_grid->view<Qtitan::GridTableView>();
    view->model()->insertRow(0);
    GridRow row = view->modelController()->getGridRowByModelRow(0);
    view->scrollToRow(row);
The following user(s) said Thank You: jia

Please Log in or Create an account to join the conversation.

More
  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to edit your message.
Moderators: Developer Machines
Time to create page: 0.159 seconds

Developer Newsletter

Join our Developer Machines newsletter to get informed on all the latest releases of the commercial components for Qt.C++, Delphi FireMonkey, updates and general knowledges.

Quick Support

Should you need any additional information about our products or licensing, please contact us at the following email addresses:

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

Get in Touch

If you would like to purchase our products or services, but don’t know how to do it the right way, please feel free to contact us:

  • This email address is being protected from spambots. You need JavaScript enabled to view it.( any questions related to our products or services )
  • This email address is being protected from spambots. You need JavaScript enabled to view it.( questions related to licensing )