Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Unsolved How to use QTextListFormat?

    General and Desktop
    1
    1
    55
    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.
    • D
      D_Tec last edited by

      Hi!

      I am currently experimenting with the Qt Quick Text Editor and wanted to extend the example with a list function. But I do not understand the documentation and could not find an example on how QTextListFormat is used. Here is what I did so far:

      // added to .h 
           Q_PROPERTY(bool ul READ ul WRITE setUl NOTIFY ulChanged)
      public:
          bool ul() const;
          void setUl(bool ul);
      
      // added to .cpp
      bool DocumentHandler::ul() const
      {
          QTextCursor cursor = textCursor();
          if (cursor.isNull())
              return false;
          qDebug()<< "is list?" << cursor.blockFormat().isListFormat();
          return cursor.blockFormat().isListFormat();
      }
      
      void DocumentHandler::setUl(bool ul)
      {
          qDebug() << "ul is: " << ul;
          QTextCursor cursor = textCursor();
          QTextListFormat list;
      
          if(ul){
              list.setStyle(QTextListFormat::ListDisc);
          }else{
              list.clearProperty(QTextListFormat::ListDisc);
          }
      
          cursor.insertList(list);
      
          emit ulChanged();
      }
      

      isListFormat always returns false. I guess I am not using it correctly. How can I check if the cursor is positioned in a list?

      setUl works for setting a list. But the list is always started in a new line and in case the cursor has a selection the selected text is deleted. Also I guess unsetting the list is done wrong as well but there is nothing in the docs on how to remove a list format from a text block.

      Could someone point me to some explanation?

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