Results 1 to 20 of 20

Thread: one model for several viewings

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #15
    Join Date
    Dec 2006
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: one model for several viewings

    I have figured everything out! Thanks so much.
    I just read it through, studied the code, read the assistent and got it all clear.
    I have done the following methods:
    Qt Code:
    1. QModelIndex myModel::addFolder(const QDir &foldername){
    2. int row = rowCount(); // number of folders already in the model
    3. insertRow(row); // add a new row
    4. QModelIndex ind = index(row, 0); // index of the newly created item
    5. insertColumn(0, ind); // add a column for future children of the item
    6. setData(ind, foldername.dirName(), Qt::DisplayRole);
    7. return ind;
    8. }
    9.  
    10. QModelIndex myModel::addFile(const QModelIndex &parent, const QFileInfo &file){
    11. int row = rowCount(parent); // get number of files
    12. insertRow(row, parent); // insert new file
    13. QModelIndex ind = index(row, 0, parent); // get index
    14. setData(ind, file.completeBaseName(), Qt::DisplayRole); // insert filename in
    15. setData(ind, file.absoluteFilePath(), Qt::UserRole); // insert full path in Qt
    16. return ind;
    17. }
    18. QModelIndex myModel::addImage(const QModelIndex &parent, const QPixmap &image){
    19. setData(parent, image, Qt::UserRole+1);
    20. return parent;
    21. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::changeItemInLV2(const QModelIndex &myIndex){
    2. imageLabel->setText(myIndex.sibling(myIndex.row(),0).data(Qt::UserRole).toString());
    3. }
    To copy to clipboard, switch view to plain text mode 
    And how to create a method to get an image from Qt::UserRole+1 I can't understand.
    QVariant doesn't have toPixmap method.
    I'm asking for your help. again.
    Last edited by someralex; 15th December 2006 at 20:12.

Similar Threads

  1. Sharing Selections between Model and ProxyModel
    By mentat in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2010, 18:31
  2. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 21:17
  3. Modify model data in QTreeView
    By YuriyRusinov in forum Qt Programming
    Replies: 6
    Last Post: 26th October 2006, 18:28
  4. Model sorting vs. selection
    By VlJE in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 17:46
  5. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 12:03

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.