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. Which control to use for this kind of report?
Forum Updated to NodeBB v4.3 + New Features

Which control to use for this kind of report?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 460 Views 3 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.
  • D Offline
    D Offline
    deleted385
    wrote on last edited by
    #1

    I wanted to achieve something like this:

    x1.gif

    With QTreeView so far I've been able to do something like this:

    x2.gif

    and I've to drag those columns to the right manually. In QTableView there's no built in grouping option, where I can give it a header style, item style and footer style. In the first GIF I've used a WPF ListBox with GroupStyle. For all sort of Financial Statements I used that technique. How to make this kind of report in Qt?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #3

      I think it's possible. Have look at:

      void QHeaderView::setSectionResizeMode(QHeaderView::ResizeMode mode)
      Sets the constraints on how the header can be resized to those described by the given mode.
      This function was introduced in Qt 5.0.
      See also sectionResizeMode(), resizeMode(), length(), and sectionResized().

      void QHeaderView::setSectionResizeMode(int logicalIndex, QHeaderView::ResizeMode mode)
      Sets the constraints on how the section specified by logicalIndex in the header can be resized to those described by the given mode. The logical index should exist at the time this function is called.
      Note: This setting will be ignored for the last section if the stretchLastSection property is set to true. This is the default for the horizontal headers provided by QTreeView.
      This function was introduced in Qt 5.0.
      See also setStretchLastSection() and resizeContentsPrecision().

      D 1 Reply Last reply
      1
      • D Offline
        D Offline
        deleted385
        wrote on last edited by deleted385
        #2

        With these:

        Window::Window(QWidget *parent) : QWidget(parent){
            auto lay = new QVBoxLayout(this);
            setLayout(lay);
            tree = new QTreeView(this);
            auto model = new QStandardItemModel(tree);
            QFontMetrics fm(font());
            int width = 0;
            model->setColumnCount(3);
            for (int i = 1; i < 4; i++) {
                auto header = new QStandardItem("Some Header " + QString::number(i));
                header->setFont(QFont(font().family(), -1, QFont::Bold, false));
                for (int j = 1; j < 3; j++) {
                    auto col1 = new QStandardItem("Some text");
                    auto col2 = new QStandardItem(QString::number(100));
                    auto col3 = new QStandardItem(QString::number(100));
                    header->appendRow(QList<QStandardItem*>() << col1 << col2 << col3);
                }
                model->appendRow(header);
                auto col1 = new QStandardItem("Total");
                auto text = QString::number(100);
                auto col2 = new QStandardItem(text);
                auto col3 = new QStandardItem(text);
                auto w = fm.boundingRect(text).width();
                if(w > width) width = w;
                model->appendRow(QList<QStandardItem*>() << col1 << col2 << col3);
            }
            tree->setModel(model);
            tree->setItemDelegate(new Delegate());
            tree->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
            tree->header()->setStretchLastSection(false);
            tree->header()->hide();
            tree->setColumnWidth(1, width);
            tree->setColumnWidth(2, width);
            tree->expandAll();
            tree->setRootIsDecorated(false);
            lay->addWidget(tree);
        }
        Window::~Window(){ }
        void Window::resizeEvent(QResizeEvent*){
            auto total = tree->width();
            auto remaining = total - tree->columnWidth(1) - tree->columnWidth(2) - tree->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
            tree->setColumnWidth(0, remaining);
        }
        

        got rid of the manual resizing issue:

        x3.gif

        Still, treeview isn't, probably, the right control to do that! If anyone knows some better way, let me know.

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mpergand
          wrote on last edited by
          #3

          I think it's possible. Have look at:

          void QHeaderView::setSectionResizeMode(QHeaderView::ResizeMode mode)
          Sets the constraints on how the header can be resized to those described by the given mode.
          This function was introduced in Qt 5.0.
          See also sectionResizeMode(), resizeMode(), length(), and sectionResized().

          void QHeaderView::setSectionResizeMode(int logicalIndex, QHeaderView::ResizeMode mode)
          Sets the constraints on how the section specified by logicalIndex in the header can be resized to those described by the given mode. The logical index should exist at the time this function is called.
          Note: This setting will be ignored for the last section if the stretchLastSection property is set to true. This is the default for the horizontal headers provided by QTreeView.
          This function was introduced in Qt 5.0.
          See also setStretchLastSection() and resizeContentsPrecision().

          D 1 Reply Last reply
          1
          • M mpergand

            I think it's possible. Have look at:

            void QHeaderView::setSectionResizeMode(QHeaderView::ResizeMode mode)
            Sets the constraints on how the header can be resized to those described by the given mode.
            This function was introduced in Qt 5.0.
            See also sectionResizeMode(), resizeMode(), length(), and sectionResized().

            void QHeaderView::setSectionResizeMode(int logicalIndex, QHeaderView::ResizeMode mode)
            Sets the constraints on how the section specified by logicalIndex in the header can be resized to those described by the given mode. The logical index should exist at the time this function is called.
            Note: This setting will be ignored for the last section if the stretchLastSection property is set to true. This is the default for the horizontal headers provided by QTreeView.
            This function was introduced in Qt 5.0.
            See also setStretchLastSection() and resizeContentsPrecision().

            D Offline
            D Offline
            deleted385
            wrote on last edited by deleted385
            #4

            @mpergand, forgot that! used that in QueryLite. With these:

            tree->header()->setSectionResizeMode(0, QHeaderView::Stretch);
            tree->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
            tree->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
            

            no need to calculate the width of text in columns and I can get rid of that resizeEvent.

            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