[SOLVED] Insert row from Qtableview to another
-
@removeRow(1); << What would happen if you don't have a row number 1 ?@
-
i have used the debugger to determine what's the issue
and i think the issue is located her
because when i delete this line every thing works perfectly
@this->item(LastRow,0)->text().isEmpty() ;@this not refering to the customQtableWidget it's reffering to the
QtableWidgetItem objet -
[quote author="SGaist" date="1374875944"]@removeRow(1); << What would happen if you don't have a row number 1 ?@[/quote]
nothing is happened , means no row have to removed , but i have correct this issue
@this->removeRow(this->rowCount()-1); @
and this should works , and finally it worksthank's for the hint
-
her is my finall code @void MonTableauWidget::keyPressEvent(QKeyEvent *event)
{
int LastRow = this->rowCount()-1;// bool ok = this->item(LastRow,0)->text().isEmpty() ;
switch (event->key()) { case Qt::Key_Down : if(LastRow) this->insertRow(this->rowCount()); break; case Qt::Key_Up : this->removeRow(LastRow); break; default: QTableWidget::keyPressEvent(event); break; }
@
-
i lost hope to get the solution from my self,
the only problem now is how to test if Cell is Empty
i use this
@this->item(row,col)->text().isEmpty(); @
but the programme crashes , what the probleme her ??
-
[quote author="advseo32" date="1374923562"]
@this->item(row,col)->text().isEmpty(); @but the programme crashes , what the probleme her ??[/quote]If there is no data in the cell, then this->item() returns NULL.
Your program will crash if you dereference a null pointer.
-
[quote author="JKSH" date="1374928103"][quote author="advseo32" date="1374923562"]
@this->item(row,col)->text().isEmpty(); @but the programme crashes , what the probleme her ??[/quote]If there is no data in the cell, then this->item() returns NULL.
Your program will crash if you dereference a null pointer.
[/quote]
Yeah! that's true , because QTableWidgetItem was created only when the user fill in the cell
do you have another way to check if the cell if not empty
-
[quote author="advseo32" date="1374942257"]do you have another way to check if the cell if not empty [/quote]If there is no data in the cell, then this->item() returns NULL :)
-
[quote author="JKSH" date="1374942566"][quote author="advseo32" date="1374942257"]do you have another way to check if the cell if not empty [/quote]If there is no data in the cell, then this->item() returns NULL :)[/quote]
Probably , you have give the answer from the the begning , but i haven't pay attention to it
yes it's works
@if (this->item(LastRow,0) != 0)@ -
now
i want to change the behavior of vertical header in Qtableview
this is what i mean:
when user start fill table cells, i want this sign(*) present in vertical header instead of numbers
when user moves beteween rows , i want also this sign(>) present in vertical header instead of numbers
what function i need to implement
-
Did you read the documentation of the various classes you are using ? For example "cellChanged":http://qt-project.org/doc/qt-4.8/qtablewidget.html#cellChanged ?
-
yes i did, but what functions are responsible for doing this
sign(*) present in vertical header instead of numbers
sign(>) present in vertical header instead of numbers
-
[quote author="SGaist" date="1374952377"]Did you read the documentation of the various classes you are using ?
[quote author="advseo32" date="1374964095"]yes i did, but what functions are responsible for...[/quote][/quote]Please read more thoroughly.Go to the "documentation":http://qt-project.org/doc/qt-5.1/qtwidgets/qtablewidget.html again and search for "header". Try different functions with good names to see what they do.
-
i have try many functions but no result
Her is my try
this function called when the user start editing cell "CellChanged Signal"
@
void Dialog::newfunction()
{
QModelIndex index ;
index = tableau->model()->index(0,0) ;
tableau->verticalHeader()->model()->setData(index,QPixmap("imgs/arrow.png"),Qt::DecorationRole);
}@
-
Good on you for trying.
[quote author="advseo32" date="1375041952"]
Her is my try
this function called when the user start editing cell "CellChanged Signal"
@
void Dialog::newfunction()
{
QModelIndex index ;
index = tableau->model()->index(0,0) ;
tableau->verticalHeader()->model()->setData(index,QPixmap("imgs/arrow.png"),Qt::DecorationRole);
}@
[/quote]There are two major issues:If you haven't set any header data, tableau->verticalHeader()->model() returns NULL
You have 2 models here. tableau->model() is the table model, tableau->verticalHeader()->model() is the header model. You created an index for the table model, so you can't use that index to set data in the header model.
Hint: If you use setHeaderData(), you don't need an index
-
i have use setHeaderData but no thing shown
@tableau->verticalHeader()->model()->setHeaderData(0,Qt::Vertical,"***", Qt::DisplayRole) ;@
-
Since you are using QTableWidget, did you take a look at this part of the "QTableWidget documentation":http://qt-project.org/doc/qt-4.8/qtablewidget.html#verticalHeaderItem ?
-
[quote author="advseo32" date="1375120030"]i have use setHeaderData but no thing shown
@tableau->verticalHeader()->model()->setHeaderData(0,Qt::Vertical,"***", Qt::DisplayRole) ;@[/quote]You are calling setHeaderData() on the header's header. Read my point #2 again.
Call setHeaderData on the table's header.
Read SGaist's link too.
-
Thank's JKSH
but really i don't get the code work perfectly, as you guide me
her my code @void Dialog::newfunction(int row,int col)
{
tableau->model()->setHeaderData(row,Qt::Vertical,"**",Qt::DisplayRole);}
@
i try the idea of SGaist's idea and it work , and hes is the code
@
void Dialog::newfunction(int row,int col)
{QTableWidgetItem * item = new QTableWidgetItem() ;
item->setIcon( *(new QIcon("imgs/editIcon.png")));
tableau->setVerticalHeaderItem(row,item);
for (int rowToDelete=0; rowToDelete < tableau->rowCount(); ++rowToDelete)
{
if(rowToDelete != row)
tableau->takeVerticalHeaderItem(rowToDelete);
}}
@the only problem now is how i can catch when the user change the selection of a spesfic row as well as the editing of cell
sorry for the my many question,
i'm newbie, but trustme i have got many for you, i think the Model/view
pattren becomes more and more easy for me , after try with your examples and hints
-
[quote author="advseo32" date="1375141407"]
@
tableau->model()->setHeaderData(row,Qt::Vertical,"**",Qt::DisplayRole);
@
[/quote]You used Qt::DecorationRole before -- that was the correct role. I'm not sure why you changed to Qt::DisplayRole.Please read up on the "ItemDataRoles":http://qt-project.org/doc/qt-5.1/qtcore/qt.html#ItemDataRole-enum.
[quote]i try the idea of SGaist's idea and it work , and hes is the code
[/quote]Congratulations! :) I'm glad you read his link and learnt how to use QTableWidget::setVerticalHeaderItem().[quote]sorry for the my many question,
i'm newbie, but trustme i have got many for you, i think the Model/view
pattren becomes more and more easy for me , after try with your examples and hints [/quote]It's ok to ask lots of questions, because that's how we learn.
But the problem is, you're not doing your research properly before asking questions. SGaist and I already gave you the link you to the QTableWidget documentation many times. Yet, you still ask us to help you find a function that is already listed on that page -- it shows us that you haven't read the page.
You're supposed to do some work too -- not just ask us to find functions for you.
Please learn to read the documentation before asking questions. Qt has very good class names and function names -- it should be easy to find the function you want by just reading the names.
[quote]the only problem now is how i can catch when the user change the selection of a spesfic row as well as the editing of cell[/quote]You haven't shown us what you've tried.
Go to the QTableWidget documentation
Read the list of “Public Functions”, “Public Slots”, and “Signals”.
When you find a function/slot/signal that sounds good, click on it and read the description.
If the description sounds good, try it in your code.
After that, if you still need help, you can ask by showing us what you've tried.