Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved How to set up headers orientation and delete check boxes?

    General and Desktop
    3
    4
    146
    Loading More Posts
    • 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.
    • V
      vme8 last edited by

      Hi!

      When the table is displayed on MySQL, headers are appearing on top as well as on the left hand side. How do I remove the left side header and check boxes and leave just the headers on top?

      Github:
      https://github.com/dawids8/Projekt2019

      You can see this issue on the picture:
      0_1568151090371_Screenshot from 2019-09-10 23-23-16.png

      Also code:

      class PatientsViewModel : public QAbstractTableModel
      {
      private:
          const std::vector<Patient>& patients;
          static const int columnsCount = 8;
          const QString columnsNames[columnsCount];
          QVariant indexToData(const QModelIndex &index) const;
      
      public:
          PatientsViewModel(const std::vector<Patient> &patients)
              :patients(patients), columnsNames  {"ID","Name","Last Name","Date of birth","PESEL","Phone Number","E-mail","Gender"}
          {
      
          }
          int rowCount(const QModelIndex &parent) const
          {
              return patients.size();
          }
          int columnCount(const QModelIndex &parent) const
          {
              return 8;
          }
          QVariant headerData(int section, Qt::Orientation orientation, int role) const
          {
              if (role != Qt::DisplayRole)
                  return QVariant();
              return columnsNames[section];
          }
          QVariant data(const QModelIndex &index, int role) const
          {
              return indexToData(index);
          }
      };
      
      QVariant PatientsViewModel::indexToData(const QModelIndex &index) const
      {
          Patient p = patients.at(index.row());
          switch (index.column())
          {
          case 0:
              return p.GetPatientId();
          case 1:
              return p.GetName();
          case 2:
              return p.GetLastName();
          case 3:
              return p.GetDateOfBirth();
          case 4:
              return p.GetPesel();
          case 5:
              return p.GetPhoneNumber();
          case 6:
              return p.GetEmail();
          case 7:
              return p.GetGender();
          }
      };
      
      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @vme8 last edited by

        @vme8
        Not sure if this is the cause/relevant, but: your data() function does not respect the role parameter, and always returns some of your actual data?

        Meanwhile, if you're using a QTableView then setHorizontal/VerticalHeader determines what you get as the horizontal and/or vertical headers.

        V 1 Reply Last reply Reply Quote 2
        • V
          vme8 @JonB last edited by

          @jonb

          I added the loop if(orientation == Qt::Horizontal) inside headerData function and I fixed the first problem, but still have this check boxes.

              QVariant headerData(int section, Qt::Orientation orientation, int role) const
              {
                  if(orientation == Qt::Horizontal)
                  {
                      if (role != Qt::DisplayRole)
                          return QVariant();
                  }
                  return columnsNames[section];
              }
          
          1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            @vme8 said in How to set up headers orientation and delete check boxes?:

            but still have this check boxes.

            @JonB already told you what to do:

            "your data() function does not respect the role parameter" - see https://doc.qt.io/qt-5/qabstractitemmodel.html#data

            Qt has to stay free or it will die.

            1 Reply Last reply Reply Quote 2
            • First post
              Last post