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. QTableView, adding headers and content
Forum Updated to NodeBB v4.3 + New Features

QTableView, adding headers and content

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 2 Posters 5.7k Views 2 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.
  • SPlattenS SPlatten

    @mrjj , I'm using Qt 5.9.2 and so far I've added:

    mptwRecs = new QTableWidget(this);
    mpsiModel = new QStandardItemModel(this);
    mptwRecs->setModel(mpsiModel);
    

    This will not compile and I get the error message:

    C2248: `QTableWidget::setModel` cannot access private member declared in class `QTableWidget`
    

    Fixed, looks like I have to use QTableView.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #8

    @SPlatten
    Hi
    yes the TableWIDGET comes with its onw internal model and it wont use external one.
    So yes., Use TreeView.

    SPlattenS 1 Reply Last reply
    0
    • mrjjM mrjj

      @SPlatten
      Hi
      yes the TableWIDGET comes with its onw internal model and it wont use external one.
      So yes., Use TreeView.

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by SPlatten
      #9

      @mrjj , did you mean TreeView or are you just trying to confuse me...more ? :)

      Kind Regards,
      Sy

      mrjjM 1 Reply Last reply
      0
      • SPlattenS SPlatten

        @mrjj , did you mean TreeView or are you just trying to confuse me...more ? :)

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #10

        @SPlatten

        Sorry :)
        I meant TableView. (no trees)

        SPlattenS 1 Reply Last reply
        0
        • mrjjM mrjj

          @SPlatten

          Sorry :)
          I meant TableView. (no trees)

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #11

          @mrjj , next related question, when I add the rows I use:

          lstRow.append(new QStandardItem(strValue));
          

          Later once the list is ready to add:

          mpsiModel->appendRow(lstRow);
          

          The question is how do I get access to the row list when I want to delete each instance of QStandardItem?

          Kind Regards,
          Sy

          mrjjM 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @mrjj , next related question, when I add the rows I use:

            lstRow.append(new QStandardItem(strValue));
            

            Later once the list is ready to add:

            mpsiModel->appendRow(lstRow);
            

            The question is how do I get access to the row list when I want to delete each instance of QStandardItem?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #12

            @SPlatten
            Hi
            Well the models own the items so you dont need to clean up. It will do.
            If you want to empty it, you can call clear() on it.

            SPlattenS 2 Replies Last reply
            1
            • mrjjM mrjj

              @SPlatten
              Hi
              Well the models own the items so you dont need to clean up. It will do.
              If you want to empty it, you can call clear() on it.

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #13

              @mrjj , thank you.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • mrjjM mrjj

                @SPlatten
                Hi
                Well the models own the items so you dont need to clean up. It will do.
                If you want to empty it, you can call clear() on it.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #14

                @mrjj , A few more tweets, each row has a lot of space and padding top and bottom of each row, including headers, I would like to remove this and also I would like to disable editing of the cells.

                I want to make it so when I double click a row it selects that row and then signals my application of this.

                Kind Regards,
                Sy

                mrjjM 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @mrjj , A few more tweets, each row has a lot of space and padding top and bottom of each row, including headers, I would like to remove this and also I would like to disable editing of the cells.

                  I want to make it so when I double click a row it selects that row and then signals my application of this.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #15

                  @SPlatten

                  hi
                  selecting row:
                  table->setSelectionBehavior(QAbstractItemView::SelectRows);

                  for nonediting, you can set that on the item

                  item->setFlags(item->flags() & ~Qt::ItemIsEditable) // we remove the edit flag. there are others flags so we only clear that one out as not to fux up stuff

                  for the spaces:

                  QHeaderView* header=tableView->verticalHeader();
                  header->setDefaultSectionSize(20); // 20 px height for all

                  SPlattenS 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    @SPlatten

                    hi
                    selecting row:
                    table->setSelectionBehavior(QAbstractItemView::SelectRows);

                    for nonediting, you can set that on the item

                    item->setFlags(item->flags() & ~Qt::ItemIsEditable) // we remove the edit flag. there are others flags so we only clear that one out as not to fux up stuff

                    for the spaces:

                    QHeaderView* header=tableView->verticalHeader();
                    header->setDefaultSectionSize(20); // 20 px height for all

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by SPlatten
                    #16

                    @mrjj ,the headers I want to resize are the horizontal headers, I tried:

                    QHeaderView* phvHorizontal(mptvRecs->horizontalHeader());
                    phvHoriztonal->setDefaultSectionSize(14);
                    

                    However that effects the header width and not the height.

                    Kind Regards,
                    Sy

                    mrjjM 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      @mrjj ,the headers I want to resize are the horizontal headers, I tried:

                      QHeaderView* phvHorizontal(mptvRecs->horizontalHeader());
                      phvHoriztonal->setDefaultSectionSize(14);
                      

                      However that effects the header width and not the height.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      @SPlatten
                      Hi
                      The verticalheader() gives access to the "height"

                      SPlattenS 2 Replies Last reply
                      0
                      • mrjjM mrjj

                        @SPlatten
                        Hi
                        The verticalheader() gives access to the "height"

                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by SPlatten
                        #18

                        @mrjj, checking this out now...also I'm using a lambda connection to connect to:

                        QObject::connect(mptvRecs, &QTableView::doubleClicked, [this, objJSONdataTypes]() {
                            ...
                        });
                        

                        This works, but is there anyway to get access to the parameter associated with the doubleClicked signal from lambda ?

                        [Edit]...trying

                        QObject::connect(mptvRecs, &QTableView::doubleClicked, [this, objJSONdataTypes](const QModelIndex& crIndex) {
                            ...
                        });
                        

                        [Edit2], yes that works!

                        Kind Regards,
                        Sy

                        1 Reply Last reply
                        1
                        • mrjjM mrjj

                          @SPlatten
                          Hi
                          The verticalheader() gives access to the "height"

                          SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by SPlatten
                          #19

                          @mrjj , Is there a way to remove the padding which seems to be present above and below the text regardless of the height setting ?

                          If I use setFixedHeight there are still several pixels above the text.

                          [Edit] Yes, by using setStyleSheet on header.

                          Kind Regards,
                          Sy

                          1 Reply Last reply
                          1

                          • Login

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