Results 1 to 2 of 2

Thread: Wrapping text of Qtableviwe cell

  1. #1
    Join Date
    Feb 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Wrapping text of Qtableviwe cell

    I am working with QtableView of Qt. I am facing one problem. I am not able to fix the content in to complete cell . In my case i have fix size of column and rows can be stretched. following is sample code


    #include <QApplication>
    #include"QStandardItemModel"
    #include"QTableView"
    #include"QStandardItem"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QStandardItemModel *model = new QStandardItemModel(8,3);
    QTableView * pQTableView = new QTableView();

    for(int r = 0;r<8;r++)
    for(int c = 0; c<3; c++)
    {
    QModelIndex index1= model->index(r,c);

    QVariant value("Swaminarayan maharaj");
    model->setData(index1, value,Qt :: DisplayRole );


    QVariant value1( Qt::AlignCenter);

    model->setData(index1, value1,Qt :: TextAlignmentRole );

    }

    pQTableView->resize(400,400);

    pQTableView->setModel(model);

    pQTableView->setColumnWidth(0, 100);
    pQTableView->setColumnWidth(1, 100);
    pQTableView->setColumnWidth(2, 100);
    pQTableView->show();

    return a.exec();
    }

    As you can see i wants each cell to have "Swaminarayan maharaj".But Swaminarayan shold be in first line of the cell and "maharaj" in second line. Inshort each cell shold display content in two lines.

  2. #2
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Wrapping text of Qtableviwe cell

    If your problem is only to display the text in two lines you can use
    Qt Code:
    1. QVariant value("Swaminarayan\nmaharaj");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. A text widget that handles line wrapping of white spaces?
    By Thuan Seah Tan in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2011, 00:17
  2. Replies: 1
    Last Post: 9th April 2011, 22:27
  3. Replies: 2
    Last Post: 11th January 2011, 22:08
  4. Word wrapping in a QTableWidget cell
    By jcooperddtd in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2007, 04:57
  5. word wrapping in QTable Cell
    By joseph in forum General Discussion
    Replies: 0
    Last Post: 27th November 2006, 10:30

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.