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 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);
        }
    }
    
    Venkatesh VV 2 Replies Last reply
    0
    • K Kushan

      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);
          }
      }
      
      Venkatesh VV Offline
      Venkatesh VV Offline
      Venkatesh V
      wrote on 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

        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);
            }
        }
        
        Venkatesh VV Offline
        Venkatesh VV Offline
        Venkatesh V
        wrote on last edited by
        #3

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

        K 1 Reply Last reply
        5
        • Venkatesh VV Venkatesh V

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

          K Offline
          K Offline
          Kushan
          wrote on last edited by
          #4
          This post is deleted!
          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