Results 1 to 11 of 11

Thread: How to connect two QListwidgets which have some data in it?

  1. #1
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to connect two QListwidgets which have some data in it?

    I have read the data from file to Qlistwidgets and now I want to do the multiple selection (using control + mouse left click) randomly 2 or 3 rows and copy the data to another listwidgets. I want the same row number selected in both list widgets.

    code for reading the data to list widgets, I didn't know how to proceed further to complete the task

    QString filename=QFileDialog::getOpenFileName(this, tr("Open File"), "media://", "All files (.);; Text File (*.txt)");

    QFile file3(filename);

    if(!file3.open(QFile::ReadOnly|QFile::Text))
    QMessageBox::information(0,"info", file3.errorString());

    else
    { QTextStream in3(&file3);

    while (!in3.atEnd()) {

    QString line = in3.readLine();

    QStringList list = line.split(" ");

    ui->xvalue->addItem(list[0]);
    ui->yvalue->addItem(list[1]);


    }
    }

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect two QListwidgets which have some data in it?

    If you always want the x and y values to be selected together then are you sure you don't want to put the data in the same QTableWidget (or model and QTableView)?

  3. #3
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to connect two QListwidgets which have some data in it?

    Quote Originally Posted by ChrisW67 View Post
    If you always want the x and y values to be selected together then are you sure you don't want to put the data in the same QTableWidget (or model and QTableView)?
    Hello,)
    Actually I don't have much idea about QTablewidget, I am very beginner to Qt. I will tell my task once, After copying the X & Y values to another (QListwidget or QTablewidget) I have to read them again and store into 1D arrays (like X[ ] and Y[ ]). So which ever option is able to do my task I am ready to take it.

    I hope you understood my task!!! Thanks a lot..

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect two QListwidgets which have some data in it?

    I would definitely use a QTableWidget then.
    Two columns (x, y), n rows.
    setSelectionBehavior() to Qt::SelectRows
    setSelectionMode() to Qt::ExtendedSelection or Qt::MultiSelection
    Access the selectionModel() or selectedItems() to determine what is selected.

  5. #5
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to connect two QListwidgets which have some data in it?

    Thank you.. I will try QTablewidget and let you know

  6. #6
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to connect two QListwidgets which have some data in it?

    Hello, I used QTableWidget and imported my data to the table and I could able to do multi selection of rows also by using the following code.

    But Problem is I am not able to get the row indices (row numbers which I select), can you help me out in finding out the row indices. I am typing the code which I have wrote for getting indices numbers

    ui->xvalue->setSelectionBehavior(QAbstractItemView::SelectRow s);
    ui->xvalue->setSelectionMode(QAbstractItemView::MultiSelectio n);


    QItemSelectionModel* selectionModel = ui->xvalue->selectionModel();

    QModelIndexList selected = selectionModel->selectedRows();
    int row;
    foreach (QModelIndex index, selected) {

    qDebug() << index.row();
    row = index.row();


    printf("\nrow = %d\n",row);

    }

    Nothing is getting printed as output.

    If i give printf() outside the curl braces, output is showing as '0'. Dont know where I am going wrong
    Thanks for your help.
    Last edited by allulks; 16th November 2015 at 16:29.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect two QListwidgets which have some data in it?

    That is exactly what you would expect if no rows are selected. Another approach would be to see what QTableWidget::selectedIndexes()has to say.

    The calls to setup the selection mode and behaviour are a one-time setup and should not be called every time you want to get the selected rows. It is quite possible these calls clear the selection.

  8. #8
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to connect two QListwidgets which have some data in it?

    Hello,

    I have done the above thing perfectly with out any problem.

    Now other task is, " If I click one push-button all rows in the QTable widget should be selected ".

    I got struck I don't know how to proceed, can you help me in solving this.

    Thanks for your help!!!

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect two QListwidgets which have some data in it?

    The QTableWidget has a selectAll() slot inherited from a base class.

    It also has the corner button that does this by default.
    http://doc.qt.io/qt-4.8/qtableview.h...onEnabled-prop

  10. #10
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to connect two QListwidgets which have some data in it?

    Hello,

    It worked thanks a lot . This is what I have done

    void Widget :: on_pushButton_3_clicked() //All rows are selected
    {
    ui->xvalue->selectAll();
    }



    void Widget :: on_pushButton_2_clicked() // Selected rows are deselected
    {
    ui->xvalue->selectionModel()->clearSelection();
    }

  11. #11
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to connect two QListwidgets which have some data in it?

    Hello,
    I am using QCustomplot for plotting the graph. I have used the code which is available in the given link for plotting the graphs.

    http://qcustomplot.com/index.php/tut.../basicplotting

    The problem what I am facing is I could not able to RESET the graph after plotting. I tried many ways for removing or clearing the graphs once reset button is clicked, unfortunately nothing has worked out.

    following code:

    ui->customplot->addGraph();
    ui->customplot->graph(0)->setData(a, b);

    ui->customplot->xAxis->setLabel("x"); //Naming X-axis
    ui->customplot->yAxis->setLabel("y"); //Naming Y-axis

    ui->customplot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle:: ssCircle));



    ui->customplot->xAxis->setRange(-1000, 1000); //X-axis range
    ui->customplot->yAxis->setRange(-1000, 1000); //Y-axis range
    ui->customplot->graph(0)->rescaleAxes(); //rescaling axes

    ui->customplot->addGraph();
    ui->customplot->graph(1)->setData(a, d);
    ui->customplot->xAxis->setLabel("x"); //Naming X-axis
    ui->customplot->yAxis->setLabel("y"); //Naming Y-axis
    ui->customplot->graph(1)->setPen(QPen(Qt::green));
    ui->customplot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle:: ssCross));
    ui->customplot->graph(1)->rescaleAxes();
    ui->customplot->replot();
    ui->customplot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);


    void Widget :: on_reset_clicked() //Reset calculation
    {
    ui->customplot->clearPlottables();

    }
    I have tried many like : cleargraphs(); cleardata(); removegraphs(); clearplottables(); nothing has worked out.

    can you please suggest me some idea about how to reset the graphs. Thanks for your help.

Similar Threads

  1. QTableWidget cells are QListWidgets resizeRowToContents
    By Henry Blue Heeler in forum Qt Programming
    Replies: 7
    Last Post: 30th January 2015, 01:57
  2. Have a single selection of item between 2 QListWidgets
    By salik89 in forum Qt Programming
    Replies: 5
    Last Post: 29th January 2014, 18:53
  3. Connect to the MYSQL server successful but can't see any data
    By stereoMatching in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2014, 04:06
  4. Drag and Drop between 2 QListWidgets
    By ShamusVW in forum Newbie
    Replies: 4
    Last Post: 28th April 2010, 13:42
  5. two qlistwidgets
    By msmihai in forum Newbie
    Replies: 1
    Last Post: 8th January 2009, 15:00

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.