Results 1 to 4 of 4

Thread: QTableWidgetItem --> Subclassing/Extanding the item informations

  1. #1
    Join Date
    May 2013
    Posts
    11
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default 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!

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    May 2013
    Posts
    11
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.

    Qt Code:
    1. #ifndef CPASAZERSKI_H
    2. #define CPASAZERSKI_H
    3. #include "csamolot.h"
    4. #include <QListWidgetItem>
    5. #include <QString>
    6.  
    7.  
    8. class CPasazerski : public CSamolot, public QListWidgetItem
    9. {
    10. public:
    11. CPasazerski(QListWidget*);
    12. CPasazerski(const QString&, QListWidget* parent = 0, int type = Type);
    13.  
    14. private:
    15. qint32 iloscPasazerow;
    16. QString miejsceDocelowe;
    17. QString liniaLotnicza;a
    18. };
    19. #endif // CPASAZERSKI_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "cpasazerski.h"
    2. #include <QListWidgetItem>
    3.  
    4. CPasazerski::CPasazerski(QListWidget * parent = 0) : QListWidgetItem(parent)
    5. {}
    6.  
    7. CPasazerski::CPasazerski(const QString &text, QListWidget *parent = 0, int type = Type) : QListWidgetItem(text)
    8. {}
    To copy to clipboard, switch view to plain text mode 

    And I''m trying bring to life an object this way:
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. if(ui->rodzajComboBox->currentText()=="Pasażerski")
    4. {
    5. lista << CPasazerski(&ui->identyfikatorLineEdit->text());
    6. //ui->hangarList->addItem(&CPasazerski(ui->identyfikatorLineEdit->text()));}
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    But the compilers says "no matching function for call to 'CPasazerski::CPasazerski(QString*)'" Why is that?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTableWidgetItem --> Subclassing/Extanding the item informations

    The class constructor needs a QString not pointer to a string. Remove the '&".
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    Noob (26th May 2013)

Similar Threads

  1. qTableWidgetItem and qwtPlot subclassing
    By chinalski in forum Qwt
    Replies: 5
    Last Post: 4th May 2012, 08:52
  2. Replies: 4
    Last Post: 29th February 2012, 21:46
  3. Replies: 2
    Last Post: 26th February 2010, 15:16
  4. QSqlRecord...retrieving informations
    By lord_shadow in forum Qt Programming
    Replies: 3
    Last Post: 5th March 2009, 12:54
  5. how to get error or informations from a exe under dos?
    By raphaelf in forum Qt Programming
    Replies: 9
    Last Post: 20th June 2008, 10:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.