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. How to set up headers orientation and delete check boxes?
Forum Updated to NodeBB v4.3 + New Features

How to set up headers orientation and delete check boxes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 364 Views
  • 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 Offline
    V Offline
    vme8
    wrote on last edited by
    #1

    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();
        }
    };
    
    JonBJ 1 Reply Last reply
    0
    • V vme8

      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();
          }
      };
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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
      2
      • JonBJ JonB

        @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 Offline
        V Offline
        vme8
        wrote on last edited by
        #3

        @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
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          • Login

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