Sample application - QTreeWidget, QTableWidget, QItemSelectionModel



  • Hello forum,

    I have a dialog window with qtreewidget and qtablewidget. Whenever the user clicks any of the tree widget item, more attribute information about the tree item will be shown in the table widget.

    If anyone is aware of any examples related to what i am looking for as mentioned above, please send me those reference examples.

    I am trying to understand the piechart example and in the mean-time i shall be grateful if something more simpler reference example or hints shows up from anyone of you.

    Regards
    Sajjad



  • I am using an example like this:

    I insert in QTableWidget data starting from a QStringList.

    @
    int w,h,pv,ph;
    QDesktopWidget d = new QDesktopWidget(); //using for discover a Screen resolution
    w= d->width()/2;
    h =d->height()/2;
    pv = w-(240);
    ph= h-(120);
    QWidget
    agr = new QWidget(this,Qt::Dialog);
    QxtTableWidget tb = new QxtTableWidget(agr);
    QVBoxLayout vb = new QVBoxLayout(agr);
    QStringList lista;
    QLabel
    lb = new QLabel(agr);
    QLineEdit
    le = new QLineEdit(agr);
    lista <<"Codigo"<<"Nome"<<"Tipo Layout";
    vb->addWidget(le);
    vb->addWidget(tb);
    vb->addWidget(lb);
    tb->setColumnCount(3);
    tb->setHorizontalHeaderLabels(lista);
    tb->horizontalHeader()->setResizeMode(1,QHeaderView::Stretch);
    agr->show();
    QPropertyAnimation propAnimationFade = new QPropertyAnimation(agr, "geometry");
    propAnimationFade->setDuration(400);
    propAnimationFade->setStartValue(QRect(pv,ph,120,0));
    propAnimationFade->setEndValue(QRect(pv,ph,480,240));
    propAnimationFade->start();
    tb->verticalHeader()->setVisible(false);
    tb->setEditTriggers(QAbstractItemView::NoEditTriggers);
    tb->setSelectionBehavior(QAbstractItemView::SelectRows);
    tb->setRowCount(1);
    QTableWidgetItem
    bitem0 = new QTableWidgetItem("text 1");
    QTableWidgetItem* bitem1 = new QTableWidgetItem("text 2");
    QTableWidgetItem* bitem2 = new QTableWidgetItem("text 3");
    tb->setItem(0,0,bitem0);
    tb->setItem(0,1,bitem1);
    tb->setItem(0,2,bitem2);
    @



  • Hi,
    You need to use a QTreeView,QTableView and a model(eg: QStandardItemModel to store the information). You also need a class to store the information/data(eg class Student { int m_rollNumber , QString m_name; }; etc ) and in the treeView u need to store the object of this class.

    When an item/object from the treeView is selected u need to cast this object to your class and then get the information and for the particular columns in tableView u can set the values. You can try this approach to create a sample application.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.