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. How to use QTextListFormat?
Forum Updated to NodeBB v4.3 + New Features

How to use QTextListFormat?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 123 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.
  • D Offline
    D Offline
    D_Tec
    wrote on last edited by
    #1

    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
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved