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. QTableView QValidator.
QtWS25 Last Chance

QTableView QValidator.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 6.2k 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.
  • C Offline
    C Offline
    cultivation
    wrote on last edited by
    #1

    Hi,

    I am displaying some editable data with a QTableView.
    I want to validate some data with a QValidator. This should be possible.
    but i cant find the needed functions.

    @Qtableview tableView;
    tableView.setmodel( ... );

    QIntValidator* intValidator(0,11,tableView);

    // tableView.setvalidator(column 2, validator intValidator);@

    Any help is appreciated, thanks.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      what exactly do you want to do?
      Validate the existing data of a table or the data the user can edit in the table?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cultivation
        wrote on last edited by
        #3

        Data input from the user.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you'll have to make a "custom item delegate":http://qt-project.org/doc/qt-4.8/qstyleditemdelegate.html setting up the validator when creating the editor

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cultivation
            wrote on last edited by
            #5

            which function creates the editor?
            @QWidget * QStyledItemDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const@

            But how will i set the validator to the widget?

            @class tableValidator : public QStyledItemDelegate
            {
            Q_OBJECT
            public:
            explicit tableValidator(QValidator* validator=0, QObject *parent = 0) : QStyledItemDelegate(parent)
            {
            Validator = validator;
            }

            virtual ~tableValidator()
            {
                
            }
            

            signals:

            public slots:

            private:
            QValidator* Validator;

            };@

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              easiest way would be probably this:
              @
              QWidget * MyDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
              {
              QWidget* editor = QStyledItemDelegate::createEditor(parent, option, index);
              QLineEdit* lineEditEditor = qobject_cast<QLineEdit*>(editor);
              if( lineEditEditor )
              lineEditEditor->setValidator(myValidator);

               return editor;
              

              }
              @

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cultivation
                wrote on last edited by
                #7

                Thanx guys.

                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