Results 1 to 20 of 20

Thread: Custom ListView. Using the model / view framework.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Location
    Porto
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Custom ListView. Using the model / view framework.

    Your code worked.

    I have another problem. When I click on the pushbutton 'Add Task' will want to add a task list that is declared in taskModel.
    I have this code but does not work ...

    Qt Code:
    1. void MainWindow::on_addTarefa_clicked()
    2. {
    3. Task t1(ui->lineNameTask->text());
    4. // t1.setContext(ui->LineContext->text());
    5. // t1.setProject(ui->lineProject->text());
    6. TaskModel model(5);
    7. model.addTask(t1);
    8.  
    9. // TaskModel::taskList.push_back(t1);
    10. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void TaskModel::addTask(const Task &task){
    2. beginInsertRows(QModelIndex(), rowCount(),rowCount());
    3. qDebug("hello");
    4. // taskList<< task;
    5. taskList.push_back(task);
    6. endInsertRows();
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2010
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 9 Times in 9 Posts

    Default Re: Custom ListView. Using the model / view framework.

    same thing here.
    you need to control the life of your objects:

    if you write:
    {
    TarefaModel model(5);
    //it lives
    }
    //it s dead

    so in your exemple you create a whole new model add an item to it and the it is destroyed at the end of your function
    1) why do you recreate a new model every time : create one model and control the content is way better.
    2) if you need to create your models use new and pass this as the parent so it will be destroyed by the parent

  3. The following user says thank you to Le_B for this useful post:

    plopes21 (2nd May 2012)

  4. #3
    Join Date
    Apr 2012
    Location
    Porto
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Custom ListView. Using the model / view framework.

    I managed to add.
    Now I am working with QAbstractItemDelegate.

    I want to use this item that I did:
    item.jpg

    I really have to use QAbstractItemDelegate?

    How do I set up my item with QAbstractItemDelegate?

    Thanks
    Last edited by plopes21; 2nd May 2012 at 17:19.

  5. #4
    Join Date
    Nov 2010
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 9 Times in 9 Posts

    Default Re: Custom ListView. Using the model / view framework.

    i think it s the way but i don't know much about delegates (i switched to QML it is way easier for that)
    but this exemple sould help you:
    http://qt-project.org/doc/qt-4.8/ite...rdelegate.html

  6. The following user says thank you to Le_B for this useful post:

    plopes21 (2nd May 2012)

  7. #5
    Join Date
    Apr 2012
    Location
    Porto
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Custom ListView. Using the model / view framework.

    I'll try to solve this problem and will post here some questions that will arise.

    Thanks Le_B

  8. #6
    Join Date
    Apr 2012
    Location
    Porto
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Custom ListView. Using the model / view framework.

    How can I put a distance between the margin items?

    I like this:

    itemsn.jpg

  9. #7
    Join Date
    Apr 2012
    Location
    Porto
    Posts
    38
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Custom ListView. Using the model / view framework.

    answer me please.

  10. #8
    Join Date
    May 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom ListView. Using the model / view framework.

    Hi plopes21,

    I think you need to add Vertical Layout to all those labels in tarefaWidget.ui.

    I am working something quite close to what you are doing and would you mind to upload your project files to have a look on how you put everything into one piece?
    Thanks

Similar Threads

  1. Replies: 9
    Last Post: 26th May 2011, 13:29
  2. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 21:23
  3. Data structure reference in Model/View Framework
    By jimc1200 in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2009, 21:23
  4. Model/View framework: streaming data in a QTableView
    By yannickt in forum Qt Programming
    Replies: 6
    Last Post: 24th October 2008, 01:06
  5. Model-view: Creating a custom view
    By taboom in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2007, 21:36

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.