Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved QDataWidgetMapper, QTextEdit storing plain text

    General and Desktop
    2
    6
    1440
    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
      cmulcahy last edited by

      OK, so my next question... I have a QTextEdit mapped to a database field via QDataWidgetMapper. Works wonderfully but I want it to store the plain text instead of HTML. Is there a magic trick to make that happen?

      Thanks in advance.

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

        @cmulcahy said:
        hi
        What about using a QPlainTextEdit instead ?

        C 1 Reply Last reply Reply Quote 0
        • C
          cmulcahy @mrjj last edited by

          @mrjj I like the simple solutions best! Unfortunately not an option because I'm showing syntax highlighting of the contents. I want the syntax highlighter to do its job for display but have the DB store the plaintext.

          This is a snippet manager. I want to use the snippets as plaintext in another context but allow the user to view and edit it with syntax highlighting.

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @cmulcahy last edited by

            @cmulcahy
            Me too but might been too easy :)
            so its soemthing like
            http://doc.qt.io/qt-5/qtwidgets-richtext-syntaxhighlighter-example.html

            Im wondering how you get the HTML back on next view?
            You insert ( highlight) at runtime so its fine to throw the HTML away?

            Have you tried with
            void QDataWidgetMapper::addMapping(QWidget *widget, int section, const QByteArray &propertyName)
            and try to see if it will accept
            plainText : QString
            property ?
            else you could subclass it and make such property.

            There is also
            void QDataWidgetMapper::setItemDelegate(QAbstractItemDelegate *delegate)

            "Sets the item delegate to delegate. The delegate will be used to write data from the model into the widget and from the widget to the model"

            Sounds like could be used.

            1 Reply Last reply Reply Quote 1
            • C
              cmulcahy last edited by

              void QDataWidgetMapper::addMapping(QWidget *widget, int section, const QByteArray &propertyName)

              That was it. No matter how many times I stared at this definition on the documentation, it never occurred to me that propertyName should be wrapped in quotes.

              mapper->addMapping(ui->scriptEditor, scriptmodel->fieldIndex("script"), "plainText");
              
              mrjj 1 Reply Last reply Reply Quote 1
              • mrjj
                mrjj Lifetime Qt Champion @cmulcahy last edited by

                @cmulcahy
                Nah, a QString would have said it more.
                or as in old times const char * -ish :)

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