How to create a bulleted or numbered list in QTextEdit with Qt by clicking a button? Also it is necessary that make a list the paragraphes which are selected by clicking the same button. And when the cursor is in the list and you click the button, the the list item becomes not-list item, but a simple paragraph. In two words I want to create for my text editer 2 buttons, that work in the same way as (buletting and numbering button is MS Word).
How to create a bulleted or numbered list with Qt?
7.4k views Asked by Narek At
2
There are 2 answers
1
serge_gubenko
On
QTextEdit should support html text formatting so button click handler below should insert 2 lists into the text edit control:
void MainWindow::on_pushButton_clicked()
{
// will insert a bulleted list
ui->textEdit->insertHtml("<ul><li>text 1</li><li>text 2</li><li>text 3</li></ul> <br />");
// will insert a numbered list
ui->textEdit->insertHtml("<ol><li>text 1</li><li>text 2</li><li>text 3</li></ol>");
}
alternatively you can manipulate textedit content using QTextDocument and QTextCursor members. Below is an example:
void MainWindow::on_pushButton_2_clicked()
{
QTextDocument* document = ui->textEdit->document();
QTextCursor* cursor = new QTextCursor(document);
QTextListFormat listFormat;
listFormat.setStyle(QTextListFormat::ListDecimal);
cursor->insertList(listFormat);
cursor->insertText("one");
cursor->insertText("\ntwo");
cursor->insertText("\nthree");
}
also this link: Rich Text Processing might be helpful
hope this helps, regards
Related Questions in C++
- How to immediately apply DISPLAYCONFIG_SCALING display scaling mode with SetDisplayConfig and DISPLAYCONFIG_PATH_TARGET_INFO
- Why can't I use templates members in its specialization?
- How to fix "Access violation executing location" when using GLFW and GLAD
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- How do I apply the interface concept with the base-class in design?
- File refuses to compile std::erase() even if using -std=g++23
- How can I do a successful map when the number of elements to be mapped is not consistent in Thrust C++
- Can std::bit_cast be applied to an empty object?
- Unexpected inter-thread happens-before relationships from relaxed memory ordering
- How i can move element of dynamic vector in argument of function push_back for dynamic vector
- Brick Breaker Ball Bounce
- Thread-safe lock-free min where both operands can change c++
- Watchdog Timer Reset on ESP32 using Webservers
- How to solve compiler error: no matching function for call to 'dmhFS::dmhFS()' in my case?
- Conda CMAKE CXX Compiler error while compiling Pytorch
Related Questions in QT
- qt c++ fonction converting adress to coordinates (longitude, latitude)
- Qml table and chart using python
- Qt: running callback in the main thread from the worker thread
- i have installed qt version 6.0.3 and this error QMYSQL driver not loaded displaying again and again
- Frameless Qt + WinAPI maximized window size is bigger than the availableGeometry()
- new window with c++ qt
- How to get scaling from transformation matrix
- How to build just Qt core libraries from Qt sources
- doxyqml not documenting qml files properly
- Incorrect assignment from a QStringList to a char * array
- How to make QT Chart size larger than widget size?
- Queued async operations with QtConcurrent interfere QImage from freed
- Questions about qt5 dynamic link library
- how to document QML files inside C++ project?
- How do I keep my screen contents centered and also have a scrollbar in QT?
Related Questions in QTEXTEDIT
- Text remaining indented after indented block when using insertHtml in QTextEdit
- QTextEdit widget Pyside6, setHtml, how to place 2 div side by side
- QTextEdit - highlighting text on input
- How to set QTextEdit formatting to preserve quote indentation, superscripts, and subscripts?
- Drawing Arrows in PyQt5 QTextEdit Relative to Text Content
- Problem with mixing Latin and Arabic text in QTextEdit
- How to copy an image from qtextedit in pyside6 and paste it into MS-WORD
- Tooltip Dissappears when Mouse Cursor Is In Tooltip Content Area
- Segmentation fault while creating QTextEdit
- How do I add a full-width horizontal line in QTextEdit?
- How to use QSizePolicy to fix height of QTextEdit in QVBoxLayout?
- Removing/hiding the extra block/line from the beginning of a QTextEdit frame
- QT6 / C++ Reading from multiple QListWidgets to singular textEdit
- how to setup the QTextDocument.FindFlag to set the search mode to search across multiple lines in PyQt6
- How to remove blank space of selected lines from QTextEdit
Related Questions in BULLETEDLIST
- Removing unwanted bullets around elementor's container
- Cannot reproduce with bullets as output of pdf document in RMarkdown
- How to put list bullet points to center
- Apply regex to catch specific bullets from list with header
- How can I extract text in bullet points from a Word file (using the python docx library)?
- Should data in in json file 'structured using li tags?
- How do I set the glyph style on all bulleted lists in a Google doc using App Script
- Bulleted List Becoming Numbered
- html - ul/li bullets not aligning when exported to pdf
- How I get the value inside of a bullet point in react?
- Creating nested bullet lists in Word using POI v5
- Why did my CSS for replacing a list item bullet with a background icon stop working?
- cannot custom bullets in list
- How to add a specific amount of periods to list item?
- Can a Notepad++ User-Defined Language be defined that provides Workflowy functionality?
Related Questions in NUMBERED
- how do you loop through javascript numbered variables?
- IP Address regex vs Numbered List
- Generating consecutive numbered urls
- VBA Access to Word error when creating numbered list
- In Python: I need to take a text file with a poem and create a copy but with numbered lines 1., 2., ect
- How to create a break in a numbered list in HTML
- Windows CMD - use numbered variables
- How do I rename multiple files after sorting by creation date?
- Calling numbered method or method named by a string
- how to remove white space content between the bullet symbol and the paragraph using OpenXML
- orgmode, referring to an item in a numbered list
- Word 2010 VBA macro to restart numbered lists
- Numbered list with text in same cell in excel
- aligned equations with mathjax, and with equation numbers
- Fixing a few thousands filenames on linux
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I have used this code:
from this source.
Only I have changed
to the following code: