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. Making Qtableview cell autosize
QtWS25 Last Chance

Making Qtableview cell autosize

Scheduled Pinned Locked Moved Solved General and Desktop
databaseretrieveqtableviewautosize
4 Posts 2 Posters 1.5k 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.
  • K Offline
    K Offline
    Kushan
    wrote on 16 Oct 2017, 10:15 last edited by
    #1

    The following code is used by me in my qt c++ application to retrieve data from a database when the user selects an option from a combo box and click the button! Though the data is retreived the text is too long to fully display in the table view cell so only a part of the text is visible! How can I adjust tableview cell size so that the the text is fully visible?

    void Dialog::on_pushButton_clicked()
    {
    {

        QSqlQueryModel *modal = new QSqlQueryModel();
        if(QSqlDatabase::contains("MyConnection")){
    
            QSqlQuery* qry=new QSqlQuery(QSqlDatabase::database("MyConnection"));
            if(ui->comboBox->currentText()=="NEW"){
    
            qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%New%' ");
            }
    
            else if(ui->comboBox->currentText()=="OLD"){
            qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%Old%' ");
            }
           
            else if(ui->comboBox->currentText()=="CANCEL"){
            qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%Cancel%' ");
            }
            
            qry->exec();
            modal->setQuery(*qry);
          ui->tableView->setModel(modal);
        }
    }
    
    V 2 Replies Last reply 16 Oct 2017, 11:32
    0
    • K Kushan
      16 Oct 2017, 10:15

      The following code is used by me in my qt c++ application to retrieve data from a database when the user selects an option from a combo box and click the button! Though the data is retreived the text is too long to fully display in the table view cell so only a part of the text is visible! How can I adjust tableview cell size so that the the text is fully visible?

      void Dialog::on_pushButton_clicked()
      {
      {

          QSqlQueryModel *modal = new QSqlQueryModel();
          if(QSqlDatabase::contains("MyConnection")){
      
              QSqlQuery* qry=new QSqlQuery(QSqlDatabase::database("MyConnection"));
              if(ui->comboBox->currentText()=="NEW"){
      
              qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%New%' ");
              }
      
              else if(ui->comboBox->currentText()=="OLD"){
              qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%Old%' ");
              }
             
              else if(ui->comboBox->currentText()=="CANCEL"){
              qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%Cancel%' ");
              }
              
              qry->exec();
              modal->setQuery(*qry);
            ui->tableView->setModel(modal);
          }
      }
      
      V Offline
      V Offline
      Venkatesh V
      wrote on 16 Oct 2017, 11:32 last edited by
      #2

      @Kushan
      Hi,

      go through the link hope it helps,
      http://doc.qt.io/qt-5/qheaderview.html#ResizeMode-enum

      1 Reply Last reply
      5
      • K Kushan
        16 Oct 2017, 10:15

        The following code is used by me in my qt c++ application to retrieve data from a database when the user selects an option from a combo box and click the button! Though the data is retreived the text is too long to fully display in the table view cell so only a part of the text is visible! How can I adjust tableview cell size so that the the text is fully visible?

        void Dialog::on_pushButton_clicked()
        {
        {

            QSqlQueryModel *modal = new QSqlQueryModel();
            if(QSqlDatabase::contains("MyConnection")){
        
                QSqlQuery* qry=new QSqlQuery(QSqlDatabase::database("MyConnection"));
                if(ui->comboBox->currentText()=="NEW"){
        
                qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%New%' ");
                }
        
                else if(ui->comboBox->currentText()=="OLD"){
                qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%Old%' ");
                }
               
                else if(ui->comboBox->currentText()=="CANCEL"){
                qry->prepare("Select DISPLAY_NAME from SER_MESSAGES where DISPLAY_NAME like '%Cancel%' ");
                }
                
                qry->exec();
                modal->setQuery(*qry);
              ui->tableView->setModel(modal);
            }
        }
        
        V Offline
        V Offline
        Venkatesh V
        wrote on 16 Oct 2017, 11:37 last edited by
        #3

        @Kushan
        Or you can use resizeColumnsToContents() method for the same.

        K 1 Reply Last reply 17 Oct 2017, 04:00
        5
        • V Venkatesh V
          16 Oct 2017, 11:37

          @Kushan
          Or you can use resizeColumnsToContents() method for the same.

          K Offline
          K Offline
          Kushan
          wrote on 17 Oct 2017, 04:00 last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0

          4/4

          17 Oct 2017, 04:00

          • Login

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