April 20, 2012

sajis997 sajis997
Lab Rat
18 posts

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

2 replies

April 20, 2012

francomartins francomartins
Hobby Entomologist
61 posts

I am using an example like this:

I insert in QTableWidget data starting from a QStringList.

  1.  int w,h,pv,ph;
  2.     QDesktopWidget *d = new QDesktopWidget(); //using for discover a Screen resolution
  3.     w= d->width()/2;
  4.     h =d->height()/2;
  5.     pv = w-(240);
  6.     ph= h-(120);
  7.     QWidget* agr = new QWidget(this,Qt::Dialog);
  8.     QxtTableWidget *tb = new QxtTableWidget(agr);
  9.     QVBoxLayout *vb = new QVBoxLayout(agr);
  10.     QStringList lista;
  11.     QLabel*  lb = new QLabel(agr);
  12.     QLineEdit*   le = new QLineEdit(agr);
  13.     lista <<"Codigo"<<"Nome"<<"Tipo Layout";
  14.     vb->addWidget(le);
  15.     vb->addWidget(tb);
  16.     vb->addWidget(lb);
  17.     tb->setColumnCount(3);
  18.     tb->setHorizontalHeaderLabels(lista);
  19.     tb->horizontalHeader()->setResizeMode(1,QHeaderView::Stretch);
  20.     agr->show();
  21.     QPropertyAnimation *propAnimationFade = new QPropertyAnimation(agr, "geometry");
  22.     propAnimationFade->setDuration(400);
  23.     propAnimationFade->setStartValue(QRect(pv,ph,120,0));
  24.     propAnimationFade->setEndValue(QRect(pv,ph,480,240));
  25.     propAnimationFade->start();
  26.     tb->verticalHeader()->setVisible(false);
  27.     tb->setEditTriggers(QAbstractItemView::NoEditTriggers);
  28.     tb->setSelectionBehavior(QAbstractItemView::SelectRows);
  29.     tb->setRowCount(1);
  30.             QTableWidgetItem*  bitem0 = new QTableWidgetItem("text 1");
  31.             QTableWidgetItem*  bitem1 = new QTableWidgetItem("text 2");
  32.             QTableWidgetItem*  bitem2 = new QTableWidgetItem("text 3");
  33.                 tb->setItem(0,0,bitem0);
  34.                 tb->setItem(0,1,bitem1);
  35.                 tb->setItem(0,2,bitem2);

April 21, 2012

Sam Sam
Area 51 Engineer
609 posts

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.

 
  ‹‹ DrawText() taking high cpu usage.      [Resolvido]Como fazer aparecer o email certo no campo de email do comit no Qt? ››

You must log in to post a reply. Not a member yet? Register here!