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. Sample application - QTreeWidget, QTableWidget, QItemSelectionModel
Qt 6.11 is out! See what's new in the release blog

Sample application - QTreeWidget, QTableWidget, QItemSelectionModel

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 5.3k Views 1 Watching
  • 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.
  • sajis997S Offline
    sajis997S Offline
    sajis997
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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);
      @

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

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