Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    QTableView QValidator.

    General and Desktop
    3
    7
    5909
    Loading More Posts
    • 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
      cultivation last edited by

      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 Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        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 Reply Quote 0
        • C
          cultivation last edited by

          Data input from the user.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • C
              cultivation last edited by

              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 Reply Quote 0
              • raven-worx
                raven-worx Moderators last edited by

                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 Reply Quote 0
                • C
                  cultivation last edited by

                  Thanx guys.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post