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. [SOLVED] Delegate at QTableView
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Delegate at QTableView

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.4k 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.
  • M Offline
    M Offline
    maxim.prishchepa
    wrote on last edited by
    #1

    Hi All, I have QTableView, at some of column I set delegate, and at that delegate create QLineEdit, and set them RegExpValidator, but some times that RegExpValidator dosen't work, and i don't understand why... :(
    code of delegate:
    @public: QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & /option/, const QModelIndex & /index/) const {
    QLineEdit * editWidget = new QLineEdit(parent);
    connect(editWidget, SIGNAL(textEdited(const QString &)), this, SLOT(onTextEdited(const QString &)));
    QString regExpStr = "[";
    //... add valid chars to regExpStr;
    regExpStr+="]*";
    QRegExp regExp(regExpStr);
    regExp.setCaseSensitivity(Qt::CaseInsensitive);
    editWidget->setValidator(new QRegExpValidator(regExp, parent));
    return editWidget;
    }
    //--------------------------------------------------------------------------------------------------
    public: void setEditorData(QWidget * editor, const QModelIndex & index) const {
    QString value = index.data(Qt::EditRole).toString();
    ((QLineEdit )editor)->setText(value);
    }
    //--------------------------------------------------------------------------------------------------
    public: void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const {
    QLineEdit * edit = (QLineEdit )editor;
    QString value = edit->text();
    model->setData(index, value, Qt::EditRole);
    }
    //--------------------------------------------------------------------------------------------------
    private slots: void onTextEdited(const QString &txt){
    ((QLineEdit
    )sender())->setText(txt.toUpper());
    }@
    variable regExpStr equals "[-XAGSRCF]
    " or "[-X#0-9]"

    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

    1 Reply Last reply
    0
    • O Offline
      O Offline
      octal
      wrote on last edited by
      #2

      What do you mean by "doesn't work" ?

      Are you sure that all your model datas are satisfying the regexp ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxim.prishchepa
        wrote on last edited by
        #3

        by “doesn’t work”, i mean so some times i (user) can write not valid data to LineEdit, but when i set a breakpoint to look what regExp set to validator, validator start work correctly.

        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxim.prishchepa
          wrote on last edited by
          #4

          no more ideas?

          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [quote author="Maxim Prishchepa" date="1314096765"]no more ideas?[/quote]
            Please practice some patience. It is not well regarded to "kick" your topic within 24 hrs of your last post.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maxim.prishchepa
              wrote on last edited by
              #6

              tnx, all for help!
              I'm solve this problem by myself.
              Validator doesn't work when the text in QLineEdit is programmatically sets to not valid.
              I solve this problem to set additional validation to the setEditorData function.

              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

              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