Results 1 to 4 of 4

Thread: Subclassing QTableWidget

  1. #1
    Join Date
    Sep 2007
    Location
    Derby, UK
    Beans
    510
    Distro
    Ubuntu 13.04 Raring Ringtail

    Subclassing QTableWidget

    I have subclassed QTableWidget and I am trying to populate it. But setItem doesnt seem to work, nothing is displayed when I run it. What am I doing wrong?

    Code:
    #include <QTableWidget>
    
    class MyTableWidget : public QTableWidget
    {
        Q_OBJECT
    public:
        MyTableWidget (QWidget *parent = 0);
        void refresh();
    
    private:
        int currentRow;
    };
    Code:
    #include "MyTableWidget .h"
    
    MyTableWidget ::MyTableWidget (QWidget *parent) : QTableWidget(parent)
    {
        refresh();
    }
    
    void MyTableWidget ::refresh()
    {
        setRowCount(1);
        setItem(0, 0, new QTableWidgetItem("test"));
    }

  2. #2
    Join Date
    Jun 2007
    Location
    Malvern, UK
    Beans
    992
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Subclassing QTableWidget

    This might be a silly question, but you are definitely new'ing up your specialised class instead of the base now?

  3. #3
    Join Date
    Sep 2007
    Location
    Derby, UK
    Beans
    510
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Subclassing QTableWidget

    In qtcreator I have a qtablewidget which I have promoted to my custom one. I know that refresh is being called because when I run it, the table displays an empty row, without the qTableWidgetItem.

  4. #4
    Join Date
    Sep 2007
    Location
    Derby, UK
    Beans
    510
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Subclassing QTableWidget

    Solved, Items weren't showing up because I had defined the columns for my custom table in the designer. Once I removed them and set them up within the constructor, it all worked.

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
  •