Thanks for the fast reply.
I found out QWidgetItemIterator already but it was just not I was looking for... I need these functions actually for a music player to go to a random next song. Example:
void MP3::playNextSong()
{
std::cout << "void MP3::playNextSong() called" << std::endl;
timer->stop();
bool found = false;
int random = rand()%10;
while(random == id)
random = rand()%10;
std::cout << "void MP3::playNextSong() rand=" << random << std::endl;
while(*it)
{
if(item && item->text(1).toInt() == random)
{
load(item->text(0).toStdString(), random);
play();
found = true;
break;
}
++it;
}
if(!found)
{
std::cout << "void MP3::playNextSong() found=false " << std::endl;
playNextSong();
}
}
void MP3::playNextSong()
{
std::cout << "void MP3::playNextSong() called" << std::endl;
timer->stop();
QTreeWidgetItemIterator it(g_main->musicList);
bool found = false;
int random = rand()%10;
while(random == id)
random = rand()%10;
std::cout << "void MP3::playNextSong() rand=" << random << std::endl;
while(*it)
{
QTreeWidgetItem* item = *it;
if(item && item->text(1).toInt() == random)
{
load(item->text(0).toStdString(), random);
play();
found = true;
break;
}
++it;
}
if(!found)
{
std::cout << "void MP3::playNextSong() found=false " << std::endl;
playNextSong();
}
}
To copy to clipboard, switch view to plain text mode
Now I'm using "rand()%10" only for testing with 10 items. But I need to know the actual count of the items in the tree, or I would have to manually change the count all the time...
Of course I can also try to make my own extended class and do this:
{
this->count++;
}
MyTreeWidget::addTopLevelItem(QTreeWidgetItem* item)
{
this->count++;
QTreeWidget::addTopLevelItem(item);
}
To copy to clipboard, switch view to plain text mode
EDIT: I just saw this function too: QTreeWidget::topLevelItemCount (). Is this the function I'm looking for?
EDIT 2: Works now . But is there a way to hide a column of a QTreeWidget?
Bookmarks