Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qlistview

Qlistview

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 589 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    veysel.olgun
    wrote on last edited by veysel.olgun
    #1

    hello i will do a seizure tracking program and i created a listview i log in name and weekday number and weekend number after that i will insert this datas in a list in the qplain text but how can i select from listview and after show it plaintextedit

    using namespace std;
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
    model =new QStringListModel(this);
    model2=new QStringListModel(this);
    model3=new QStringListModel(this);
    model4=new QStringListModel(this);
    QStringList list;
    QStringList list2;
    QStringList list3;
    QStringList list4;
    
    qsrand(time(NULL));
    
    random = qrand() %30;
    qDebug()<<random;
    //list2<<"sayi"<<"sayi";
    
    model->setStringList(list);
    model2->setStringList(list2);
    model3->setStringList(list3);
    model4->setStringList(list4);
    ui->listView->setModel(model);
    ui->listView_2->setModel(model2);
    ui->listView_3->setModel(model3);
    qDebug()<<model2;
    
    ui->listView->setEditTriggers(QAbstractItemView::AnyKeyPressed | QAbstractItemView::DoubleClicked);
    ui->listView_2->setEditTriggers(QAbstractItemView::AnyKeyPressed | QAbstractItemView::DoubleClicked);
    ui->listView_3->setEditTriggers(QAbstractItemView::AnyKeyPressed | QAbstractItemView::DoubleClicked);
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_add_clicked()
    {
    int row = model->rowCount();
    int row2 = model2->rowCount();
    int row3 = model3->rowCount();
    
    model->insertRows(row,1);
    model2->insertRows(row2,1);
    model3->insertRows(row3,1);
    
    QModelIndex index=model->index(row);
    QModelIndex index2=model2->index(row2);
    QModelIndex index3=model3->index(row3);
    
    ui->listView->setCurrentIndex(index);
    ui->listView_2->setCurrentIndex(index2);
    ui->listView_3->setCurrentIndex(index3);
    ui->listView->edit(index);
    ui->listView_2->edit(index2);
    ui->listView_3->edit(index3);
    ui->plainTextEdit->insertPlainText();
    
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      The listview has a signals for when you click an item.
      Like
      clicked(const QModelIndex &index)
      if you want to take it when clicked.

      You can also do
      QModelIndex index = ui->listView->currentIndex();
      QString itemText = index.data(Qt::DisplayRole).toString();
      To take the currently selected/active item.

      If you need more than one selected there is
      ui->listView->selectionModel()->selectedIndexes())
      which gives a list of all selected indexes.

      1 Reply Last reply
      2
      • V Offline
        V Offline
        veysel.olgun
        wrote on last edited by
        #3

        hello mrjj, it works fine, thank you for your help

        have a good day

        mrjjM 1 Reply Last reply
        1
        • V veysel.olgun

          hello mrjj, it works fine, thank you for your help

          have a good day

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @veysel.olgun
          Hi
          same to you.
          Please set topic to solved if you are happy with answer.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            veysel.olgun
            wrote on last edited by veysel.olgun
            #5

            i am happy with answer thank you i set topic to solved

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved