PDA

View Full Version : list box alignment problem



maarvi
28th June 2011, 08:17
hello every one i am facing a problem . i have a list view in which i am displaying the items retrieved from the file my file is my file each line of file contain tab separated entries (sample file attached) but when i display it in my list view, item didnt appear aligned.here is the code


void list_load(QStandardItem * root)
{
FILE * f;
f=fopen("/home/cv/mod2an3run/output/mod3run/sample.txt","r");
if(f==NULL)
{ printf("not open");
root->appendRow(new QStandardItem("ash"));

}
QString buffer ="";

char ch = ' ';

while (ch!=EOF)
{

ch = fgetc(f);
if(ch!='\n')
{
buffer = buffer+ch;
}

if(ch=='\n')
{

QString status= range(prob);
buffer = buffer +"\t"+ status ;
root->appendRow(new QStandardItem(buffer));
buffer="";
}

} //while end
fclose(f);

}// func end


i have attached my interface and sample file out put kindly help me to align my list box items

Rachol
28th June 2011, 08:31
It seems like your file containing tab separated entries is broken. Make sure that you don't have 2 tabs between entries in the line.

You can also try to fix your buffer string in the code:


buffer.replace(QRegExp("[\t]+"), "\t");

But if you don't want to get into some troubles later on, you should place each string in a seperate cell, hence using a table would be helpful.

Santosh Reddy
28th June 2011, 08:48
This is a classics problem while using tabs in text file, a lasting solution is split each row into individual cells, as Rachol suggested.