Results 1 to 6 of 6

Thread: setColumnWidth problem

  1. #1
    Join Date
    May 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default setColumnWidth problem

    setColumnWidth doesn't work for me. Here is my code:

    treeExample::treeExample(QWidget *parent)
    : QWidget(parent)
    {
    ui.setupUi(this);

    QStandardItem *item;
    model = new QStandardItemModel(0,3);

    model->setHeaderData(0,Qt::Horizontal,QObject::tr("Date" ));
    model->setHeaderData(1,Qt::Horizontal,QObject::tr("Time" ));
    model->setHeaderData(2,Qt::Horizontal,QObject::tr("Proc" ));

    item = new QStandardItem("First");
    model->setItem(0, 0, item);

    item = new QStandardItem("Sec");
    model->setItem(0, 1, item);

    item = new QStandardItem("Thi");
    model->setItem(0, 2, item);

    QTreeView *tree = ui.treeView;

    tree->setModel(model);
    tree->setColumnWidth(0,100);
    tree->setColumnWidth(1,20);

    tree->show();

    }


    What is wrong?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: setColumnWidth problem

    What does not work? This works fine for me:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. QStandardItemModel model(1,3);
    8. model.setHeaderData(0,Qt::Horizontal,QObject::tr("Date" ));
    9. model.setHeaderData(1,Qt::Horizontal,QObject::tr("Time" ));
    10. model.setHeaderData(2,Qt::Horizontal,QObject::tr("Proc" ));
    11.  
    12. model.setItem(0, 0, new QStandardItem("First"));
    13. model.setItem(0, 1, new QStandardItem("Second"));
    14. model.setItem(0, 2, new QStandardItem("Third"));
    15.  
    16. QTreeView tree;
    17. tree.setModel(&model);
    18. tree.setColumnWidth(0,100);
    19. tree.setColumnWidth(1,20);
    20. tree.show();
    21.  
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setColumnWidth problem

    column width is not changed, fist and second columns have same width.

  4. #4
    Join Date
    May 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setColumnWidth problem

    In your example, ti works, in my not. What is the difference?

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: setColumnWidth problem

    well you use a designer file. In there you probably have set different options for your view...

  6. #6
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setColumnWidth problem

    Hello,

    I have the same problem and I want to know if you have been able to solve your problem. What should the options be set?

    Thanks...

Similar Threads

  1. QTableView ::setColumnWidth not working?
    By killerwookie99 in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2008, 17:14

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.