QTableWidgetItem --> Subclassing/Extanding the item informations
So I have to start from begining,
I need to have a class of item that contains a few information about the object. But on the table, I only want to display the name of an item. The whole rest of informtion I want to display in other place, not the table.
So I want to make a subclass inheriting from QTableWidgetItem in which I want to place the extanded information about the item (a bounch o QStrings and some qints, bools).
I am not sure how to write this class. What methods do I need to overload? I see there is a data() method, and this method returns the value for the given role. And here I stucked a bit, What are that role in fact?? If could you describe me how does it works, I will be thankfull.
Thanks for any hint!
Re: QTableWidgetItem --> Subclassing/Extanding the item informations
To start with data() will be sufficient for read-only table, if editing is required then setData() has to be implemented. Role here is Qt::ItemDataRole, all the item specific data that is hidden from the table can be stored in Qt::UserRole + 1, 2, 3.. etc.
Re: QTableWidgetItem --> Subclassing/Extanding the item informations
Thanks for answer.
unfortunetly I am after long break, and have to ask about some more basic stuff.
Code:
#ifndef CPASAZERSKI_H
#define CPASAZERSKI_H
#include "csamolot.h"
#include <QListWidgetItem>
#include <QString>
{
public:
CPasazerski
(const QString
&,
QListWidget* parent
= 0,
int type
= Type
);
private:
qint32 iloscPasazerow;
};
#endif // CPASAZERSKI_H
Code:
#include "cpasazerski.h"
#include <QListWidgetItem>
{}
{}
And I''m trying bring to life an object this way:
Code:
void MainWindow::on_pushButton_clicked()
{
if(ui->rodzajComboBox->currentText()=="Pasażerski")
{
lista << CPasazerski(&ui->identyfikatorLineEdit->text());
//ui->hangarList->addItem(&CPasazerski(ui->identyfikatorLineEdit->text()));}
}
}
But the compilers says "no matching function for call to 'CPasazerski::CPasazerski(QString*)'" Why is that?
Re: QTableWidgetItem --> Subclassing/Extanding the item informations
The class constructor needs a QString not pointer to a string. Remove the '&".