Results 1 to 3 of 3

Thread: list box alignment problem

  1. #1
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default list box alignment problem

    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
    Qt Code:
    1. void list_load(QStandardItem * root)
    2. {
    3. FILE * f;
    4. f=fopen("/home/cv/mod2an3run/output/mod3run/sample.txt","r");
    5. if(f==NULL)
    6. { printf("not open");
    7. root->appendRow(new QStandardItem("ash"));
    8.  
    9. }
    10. QString buffer ="";
    11.  
    12. char ch = ' ';
    13.  
    14. while (ch!=EOF)
    15. {
    16.  
    17. ch = fgetc(f);
    18. if(ch!='\n')
    19. {
    20. buffer = buffer+ch;
    21. }
    22.  
    23. if(ch=='\n')
    24. {
    25.  
    26. QString status= range(prob);
    27. buffer = buffer +"\t"+ status ;
    28. root->appendRow(new QStandardItem(buffer));
    29. buffer="";
    30. }
    31.  
    32. } //while end
    33. fclose(f);
    34.  
    35. }// func end
    To copy to clipboard, switch view to plain text mode 


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

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: list box alignment problem

    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:

    Qt Code:
    1. buffer.replace(QRegExp("[\t]+"), "\t");
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by Rachol; 28th June 2011 at 08:38.

  3. #3
    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: list box alignment problem

    This is a classics problem while using tabs in text file, a lasting solution is split each row into individual cells, as Rachol suggested.

Similar Threads

  1. QTableView - alignment/selection problem
    By Nesbitt in forum Qt Programming
    Replies: 7
    Last Post: 30th November 2009, 02:37
  2. Q3Table text alignment problem
    By batileon in forum Qt Programming
    Replies: 4
    Last Post: 28th August 2008, 18:04
  3. child label alignment problem
    By ht1 in forum Qt Programming
    Replies: 9
    Last Post: 21st November 2007, 20:50
  4. Still facing Alignment problem in QTable
    By joseph in forum Qt Programming
    Replies: 5
    Last Post: 15th December 2006, 12:40
  5. problem with alignment
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2006, 12:52

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
  •  
Qt is a trademark of The Qt Company.