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:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->trackList->setRowCount(0);
ui->trackList->setColumnWidth(0, 260);
ui->trackList->setColumnWidth(1, 260);
ui->trackList->setColumnWidth(2, 68);
rowCount = 0;
playButtonPixmap
= new QPixmap(":/images/play_button.png");
playButtonIcon
= new QIcon(*playButtonPixmap
);
ui->addButton->setIcon(*playButtonIcon);
ui
->addButton
->setIconSize
(QSize(20,
20));
QPixmap mainwindowIconPixmap
(":/images/play_button.png");
QIcon mainwindowIcon
(mainwindowIconPixmap
);
setWindowIcon(mainwindowIcon);
setWindowTitle("MK3 - Liveset player");
testTable(ui->trackList);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->trackList->setRowCount(0);
ui->trackList->setColumnWidth(0, 260);
ui->trackList->setColumnWidth(1, 260);
ui->trackList->setColumnWidth(2, 68);
rowCount = 0;
playButtonPixmap = new QPixmap(":/images/play_button.png");
playButtonIcon = new QIcon(*playButtonPixmap);
ui->addButton->setIcon(*playButtonIcon);
ui->addButton->setIconSize(QSize(20,20));
QPixmap mainwindowIconPixmap(":/images/play_button.png");
QIcon mainwindowIcon(mainwindowIconPixmap);
setWindowIcon(mainwindowIcon);
setWindowTitle("MK3 - Liveset player");
testTable(ui->trackList);
}
To copy to clipboard, switch view to plain text mode
And this is what the function looks like:
{
table->setRowCount(2);
artist->setText("Akon");
title->setText("Yeah!");
time->setText("00:01:00");
table->setItem(0, 0, artist);
table->setItem(0, 1, title);
table->setItem(0, 2, time);
artist->setText("Justin Bieber");
title->setText("Sorry");
time->setText("00:03:00");
table->setItem(1, 0, artist2);
table->setItem(1, 1, title2);
table->setItem(1, 2, time2);
}
void MainWindow::testTable(QTableWidget *table)
{
table->setRowCount(2);
QTableWidgetItem *artist = new QTableWidgetItem;
artist->setText("Akon");
QTableWidgetItem *title = new QTableWidgetItem;
title->setText("Yeah!");
QTableWidgetItem *time = new QTableWidgetItem;
time->setText("00:01:00");
table->setItem(0, 0, artist);
table->setItem(0, 1, title);
table->setItem(0, 2, time);
QTableWidgetItem *artist2 = new QTableWidgetItem;
artist->setText("Justin Bieber");
QTableWidgetItem *title2 = new QTableWidgetItem;
title->setText("Sorry");
QTableWidgetItem *time2 = new QTableWidgetItem;
time->setText("00:03:00");
table->setItem(1, 0, artist2);
table->setItem(1, 1, title2);
table->setItem(1, 2, time2);
}
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
Bookmarks