-
Table view
Hello
I'm trying to make a app with table view.
I want to make some kind of parking lot where each table item has a ID. Any one who can help me?
Should i use table view og table widget?
I also want to change the color when a item with a cirtan ID is taken. Green color when it is free and red when it is taken.
-
Re: Table view
It's easier to use QTableWidget, but QTableView is more flexible.
You can change color of a cell with QAbstractItemModel::setData() changing brush for Qt::BackgroundRole
[url]http://doc.qt.nokia.com/4.7/qabstractitemmodel.html#setData[/url]
[url]http://doc.qt.nokia.com/4.7/qtablewidget.html#item[/url]
[url]http://doc.qt.nokia.com/4.7/qtablewidgetitem.html#setData[/url]
-
Re: Table view
Thanks for your reply.
I have made a tableview with the widget, so it must be the tablewidget. And i clicked go to slot where i choose the cellpressed. But i don't know if it is the right way to do it.
I still want to change the color of a item in the table. But i don't know how to use these.
If it was the right way to set up the widget, is the code i got from the CPP file here:
void MainWindow::on_tableWidget_cellPressed(int row, int column)
{
}
When i press the item the backgroundcolor should change
-
Re: Table view
Two last links from my previous post explain how to achieve what you want.
How to get pointer to QTableWidget in the slot:
[url]http://doc.qt.nokia.com/4.7/qobject.html#sender[/url]
-
Re: Table view
I appreciate your reply, but i'm a noob, so if you could help me by writing the actural code, so i understand what you mean when you tell me how to use ex this code QAbstractItemModel:setData();
I have made a table widget in the UI, which is called tableWidget and i have made a pushButton, so when the button is clicked the background of a item in the tableview would change color from green to red.