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. Set column as not editable in QTableWidget

Set column as not editable in QTableWidget

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 20.2k Views 1 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.
  • V Offline
    V Offline
    Vidhya
    wrote on last edited by
    #1

    @connect(ui->widget,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(column_check(int,int)));

    void Saleorder::column_check(int row,int column)
    {
    QTableWidgetItem* itemtot=ui->widget->item(row, 9);

    if( column == 9 )
    {
        if (itemtot && !itemtot->text().isEmpty())
        {
            itemtot->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
        }
    
    }
    

    }@

    i tried this but the program is crashed.

    Any one help me solve the problem.

    Is there is any other way to achieve to make the entire column as not editable

    Thanks in advance

    Regards,
    Vidhya

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      Have you tried unsetting Qt::ItemIsEditable on the respective cells on row creation (not on click)?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        check "this":http://qt-project.org/forums/viewthread/16254/.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vidhya
          wrote on last edited by
          #4

          S i tried the same code on row creation also

          Regards,
          Vidhya

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            Did you get it working ?

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vidhya
              wrote on last edited by
              #6

              no its not working . because at first the item is empty

              Regards,
              Vidhya

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vidhya
                wrote on last edited by
                #7

                @
                Qt::ItemFlags Saleorder::flags( const QModelIndex &index) const
                {
                Qt::ItemFlags flags = QSqlTableModel::flags(index);
                if (index.column() == 9 )
                flags &= ~Qt::ItemIsEditable;
                return flags;
                }@

                i use this but it displays the below error message.
                saleorder.cpp:98: error: cannot call member function 'virtual Qt::ItemFlags QSqlTableModel::flags(const QModelIndex&) const' without object

                Regards,
                Vidhya

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  KA51O
                  wrote on last edited by
                  #8

                  [quote author="Vidhya" date="1343736279"]
                  i use this but it displays the below error message.
                  saleorder.cpp:98: error: cannot call member function 'virtual Qt::ItemFlags QSqlTableModel::flags(const QModelIndex&) const' without object[/quote]

                  Read the compiler message.
                  flags is not a static function and thus needs an object to be called from. So this:
                  @
                  Qt::ItemFlags flags = QSqlTableModel::flags(index);
                  @
                  is not valid code.
                  If saleorder is derived from QSqlTableModel (which i'd doubt) you can do this:
                  @
                  Qt::ItemFlags flags = flags(index);
                  @
                  otherwise you need a QSqlTableModel object
                  @
                  Qt::ItemFlags flags = someQSqlTableModelObject.flags(index);
                  //or
                  Qt::ItemFlags flags = someQSqlTableModelObjectPointer->flags(index);
                  @
                  Maybe this will work in your case:
                  @
                  Qt::ItemFlags flags = ui->widget->model()->flags(index);
                  @

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    francomartins
                    wrote on last edited by
                    #9

                    try it :

                    // Qt::noItemFlags disable all flags , and u can add the flags again ;
                    @
                    void Saleorder::column_check(int row,int column)
                    {
                    if (!ui->widget->item(row, 9)->text().isEmpty())
                    {
                    ui->widget->item(row,9)->setFlags(Qt::NoItemFlags|Qt::ItemIsSelectable|Qt::ItemIsEnabled);
                    }
                    }
                    @

                    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