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. QDataWidgetMapper, QTextEdit storing plain text

QDataWidgetMapper, QTextEdit storing plain text

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.9k 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
    cmulcahy
    wrote on last edited by
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      C 1 Reply Last reply
      0
      • mrjjM mrjj

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

        C Offline
        C Offline
        cmulcahy
        wrote on last edited by
        #3

        @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.

        mrjjM 1 Reply Last reply
        0
        • C cmulcahy

          @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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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
          1
          • C Offline
            C Offline
            cmulcahy
            wrote on last edited by
            #5

            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");
            
            mrjjM 1 Reply Last reply
            1
            • C cmulcahy

              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");
              
              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              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