Results 1 to 12 of 12

Thread: QTableView add row

  1. #1
    Join Date
    Apr 2011
    Location
    italy
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTableView add row

    QTableView add row
    Hi guys,
    i tried in various way to add row in QTableView without using QSqlQueryModel.
    I'd like to create a table then for each row is describes in 3 colums:

    Qt Code:
    1. ______________________________________________________
    2. _________
    3. | | Nane: ..... _________
    4. | IMAGE | Description: ........ | button |
    5. | | |____ok___|
    6. |________|
    7.  
    8. ______________________________________________________
    To copy to clipboard, switch view to plain text mode 

    for image i use a QLabel, and i'd like to use the same thing for Name and Description, But I don't know how create a model for rows, and insert data..
    Someone can help me?

    Thanks.

  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: QTableView add row

    If you arer not sure how to implement model, then you can QTableWidget, it be simple to use, and still does what you want.

  3. #3
    Join Date
    Apr 2011
    Location
    italy
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView add row

    thank you,
    i try to use QTableWidget, but however i don't understand how to add items in row...
    i try:

    Qt Code:
    1. ui->tableWidgetAll->insertRow(1);
    2. ui->tableWidgetAll->insertColumn(1);
    3.  
    4. ui->tableWidgetAll->setItem(0,0, i);
    To copy to clipboard, switch view to plain text mode 

    but there isn't no change in table

  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: QTableView add row

    you need to add new row, and then setItem()
    Qt Code:
    1. ui->tableWidgetAll->insertRow(0);
    To copy to clipboard, switch view to plain text mode 

    also note that row and column index start from 0 (not from 1)

  5. #5
    Join Date
    Apr 2011
    Location
    italy
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView add row

    ok, thank you again i've understand than the int describes the numbers of row to add.

    How i add new item?
    like this?

    Qt Code:
    1. ui->tableWidgetAll->setItem(0,0,QTableWidgetItem(??));
    To copy to clipboard, switch view to plain text mode 

  6. #6
    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: QTableView add row

    Qt Code:
    1. ui->tableWidgetAll->setItem(0,0, new QTableWidgetItem("Item Text")); //this will set the item on row 0 column 0
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Apr 2011
    Location
    italy
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView add row

    like this
    Qt Code:
    1. ui->tableWidgetAll->insertRow(0);
    2.  
    3. item->setText("test");
    4. ui->tableWidgetAll->setItem(0, 0, item);
    To copy to clipboard, switch view to plain text mode 

    add new row, but no text is shown

  8. #8
    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: QTableView add row

    Did you read QTableWidgetItem Documnetation, I suggest to have look at it.

  9. #9
    Join Date
    Apr 2011
    Location
    italy
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView add row

    Thank you for your help!
    I read the documentation... but in the documentation there isn't any example.....
    In some way i've done what i need.

    Qt Code:
    1. ui->tableWidgetAll->setRowHeight(0,100);
    2. ui->tableWidgetAll->insertColumn(0);
    3. ui->tableWidgetAll->insertColumn(1);
    4. ui->tableWidgetAll->insertColumn(2);
    5. ui->tableWidgetAll->insertRow(0);
    6.  
    7.  
    8. item1->setIcon(QIcon(":/immagine1.jpg"));
    9. ui->tableWidgetAll->setItem(0, 0, item1);
    10.  
    11. item2->setText("test");
    12. ui->tableWidgetAll->setItem(0, 1, item2);
    13.  
    14. item3->;
    15. ui->tableWidgetAll->setItem(0, 3, item3);
    To copy to clipboard, switch view to plain text mode 

    The last 2 questions,
    1)how to create a QButton in item3?
    2)how to do function if i click in item2 or item1? [like a button]

    thank you again , and excuse me for all my questions

  10. #10
    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: QTableView add row

    Qt Code:
    1. QPushButton * button = new QPushButton("Push Me to Emit Signal");
    2.  
    3. connect(button, SIGNAL(clicked()), this, SLOT(MySlot()));
    4.  
    5. ui->tableWidgetAll->setCellWidget(0, 2, button); // this will set the QPushButton on row 0, column 2, i.e 1st Row and 3rd Column in table
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Android Maemo/MeeGo

    Default Re: QTableView add row

    Hi All,
    I want to develop this type of grid view like after clicking edit button for each row of table please refer this link
    "http://www.c-sharpcorner.com/uploadfile/1e050f/edit-and-update-record-in-gridview-in-asp-net/" .....guide me for implementing same grid view using Qt and MS Sql server.....

  12. #12
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Android Maemo/MeeGo

    Default Re: QTableView add row

    Hi All,
    I want to develop this type of grid view like after clicking edit button for each row of table please refer this link
    "http://www.c-sharpcorner.com/uploadfile/1e050f/edit-and-update-record-in-gridview-in-asp-net/" .....guide me for implementing same grid view using Qt and MS Sql server.....

Similar Threads

  1. QTableView and QLineEdit OUTSIDE of QTableView, like Excel
    By JoZCaVaLLo in forum Qt Programming
    Replies: 10
    Last Post: 13th May 2011, 14:20
  2. Get the value from QTableview
    By umulingu in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2010, 10:55
  3. Replies: 2
    Last Post: 26th November 2009, 05:45
  4. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 17:53
  5. QTableView - Add Row
    By maxpower in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2006, 19:18

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.