PDA

View Full Version : QTableWidgetItem --> Subclassing/Extanding the item informations



Noob
24th May 2013, 17:16
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!

Santosh Reddy
24th May 2013, 17:48
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.

Noob
24th May 2013, 18:54
Thanks for answer.

unfortunetly I am after long break, and have to ask about some more basic stuff.



#ifndef CPASAZERSKI_H
#define CPASAZERSKI_H
#include "csamolot.h"
#include <QListWidgetItem>
#include <QString>


class CPasazerski : public CSamolot, public QListWidgetItem
{
public:
CPasazerski(QListWidget*);
CPasazerski(const QString&, QListWidget* parent = 0, int type = Type);

private:
qint32 iloscPasazerow;
QString miejsceDocelowe;
QString liniaLotnicza;a
};
#endif // CPASAZERSKI_H



#include "cpasazerski.h"
#include <QListWidgetItem>

CPasazerski::CPasazerski(QListWidget * parent = 0) : QListWidgetItem(parent)
{}

CPasazerski::CPasazerski(const QString &text, QListWidget *parent = 0, int type = Type) : QListWidgetItem(text)
{}


And I''m trying bring to life an object this way:

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?

Santosh Reddy
25th May 2013, 20:51
The class constructor needs a QString not pointer to a string. Remove the '&".