Results 1 to 3 of 3

Thread: Problem setting items in QTableWidget

  1. #1
    Join Date
    May 2016
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Problem setting items in QTableWidget

    Hello everyone,

    In the constructor for my Mainwindow I set some parameters for a QTableWidget I placed with the design editor. After that I am calling a memberfunction (testTable) that should fill two rows of the table. Here is the code of the constructor:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. ui->trackList->setRowCount(0);
    7. ui->trackList->setColumnWidth(0, 260);
    8. ui->trackList->setColumnWidth(1, 260);
    9. ui->trackList->setColumnWidth(2, 68);
    10. rowCount = 0;
    11.  
    12. playButtonPixmap = new QPixmap(":/images/play_button.png");
    13. playButtonIcon = new QIcon(*playButtonPixmap);
    14. ui->addButton->setIcon(*playButtonIcon);
    15. ui->addButton->setIconSize(QSize(20,20));
    16.  
    17. QPixmap mainwindowIconPixmap(":/images/play_button.png");
    18. QIcon mainwindowIcon(mainwindowIconPixmap);
    19. setWindowIcon(mainwindowIcon);
    20. setWindowTitle("MK3 - Liveset player");
    21.  
    22. testTable(ui->trackList);
    23. }
    To copy to clipboard, switch view to plain text mode 

    And this is what the function looks like:
    Qt Code:
    1. void MainWindow::testTable(QTableWidget *table)
    2. {
    3. table->setRowCount(2);
    4.  
    5. artist->setText("Akon");
    6.  
    7. title->setText("Yeah!");
    8.  
    9. time->setText("00:01:00");
    10.  
    11. table->setItem(0, 0, artist);
    12. table->setItem(0, 1, title);
    13. table->setItem(0, 2, time);
    14.  
    15. artist->setText("Justin Bieber");
    16.  
    17. title->setText("Sorry");
    18.  
    19. time->setText("00:03:00");
    20.  
    21. table->setItem(1, 0, artist2);
    22. table->setItem(1, 1, title2);
    23. table->setItem(1, 2, time2);
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    Now the problem is that whenever I run the application it only fills the top row of the table. It only shows Justin Bieber in the top row and Akon is nowhere to be found. But if I comment out the Justin Bieber part in my code, Akon is visible. What I recon is that it does not respond to the row I set in table->setItem.

    Thanks in advance!
    Martijn

  2. #2
    Join Date
    Jan 2011
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem setting items in QTableWidget

    In 19, 22 and 25 line, you should change variable name from *** to ***2.

  3. #3
    Join Date
    May 2016
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem setting items in QTableWidget

    Currently having the biggest facepalm ever -_- Thanks a lot!!!

Similar Threads

  1. QTableWidget - problem when editing multiple items
    By xportation in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2011, 11:38
  2. Setting two horizontal header labels for QTablewidget
    By arunvv in forum Qt Programming
    Replies: 2
    Last Post: 20th August 2009, 18:58
  3. Setting background colors to rows in QTableWidget
    By cnbp173 in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2009, 18:38
  4. Replies: 2
    Last Post: 5th March 2009, 11:34
  5. Replies: 3
    Last Post: 10th April 2006, 20:04

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.