qtextedit

Clickable hyperlink in QTextEdit

╄→尐↘猪︶ㄣ 提交于 2019-12-05 03:03:55
I want to use QTextEdit (in read-only mode) to show a clickable hyperlink, I used to do QTextEdit *textEdit = new QTextEdit; QTextCursor cursor(textEdit->document()); textEdit->setTextCursor(cursor); cursor->insertHtml("<a href=\"www.google.com\" >Google</a>"); textEdit->show(); this code will show Google as hyperlink but unable to click. And if I used QTextEdit *textEdit = new QTextEdit; QTextCursor cursor(textEdit->document()); textEdit->setTextCursor(cursor); QTextCharFormat linkFormat = cursor.charFormat(); linkFormat.setAnchor(true); linkFormat.setAnchorHref("http://www.google.com");

How to change row height in QTextTable

三世轮回 提交于 2019-12-04 22:15:31
I'm writing the complicated rich text editor, derived from QTextEdit class. It must be able to insert, resize, and apply various formatting to embedded tables. I found function for setup column widths ( setColumnWidthConstraints ). But there is no one to change _rows_ heights . Is there any way to achieve this? Example code: void CustomTextEdit::insertTable (int rows_cnt, int columns_cnt) { QTextCursor cursor = textCursor (); QTextTableFormat table_format; table_format.setCellPadding (5); // TODO: This call just changed the frame border height, not table itself. //table_format.setHeight (50);

How to access QTextDocument pages

懵懂的女人 提交于 2019-12-04 16:33:30
I am trying to build an application that would display rich text documents in paginated fashion - more or less like MS Word does. For now, I would like to have only one page displayed at a time. From this question I have learned that I need to represent the document by QTextDocument . While the author of the question focuses more on the view representation, I would like to learn about accessing document data in paginated fashion. I can see that the class has methods such as setPageSize() and pageCount() . Calling setPageSize() seems to update pageCount() accordingly. The problem is I do not

Connecting multiple signals to a single slot in Qt

♀尐吖头ヾ 提交于 2019-12-04 15:38:11
I'm trying to keep track of the textChanged() signal on for handful of QTextEdits. I want to do the same thing regardless of the text edit emitting the signal: uncheck its associated checkbox in a QListWidget if it becomes empty and leave it checked otherwise. The function I have so for is as follows: void MainWindow::changed() { QString tempStr = ui->hNMRedit->toPlainText(); if(tempStr != "") { ui->checkList->item(0)->setCheckState(Qt::Checked); } else { ui->checkList->item(0)->setCheckState(Qt::Unchecked); } } With the current approach, I would have to make a function like this for every

How to give QTextFrame or QTextBlock a background-image in QTextEdit?

雨燕双飞 提交于 2019-12-04 08:05:13
I am developing an IM tool,as a part of it I have to develop a BubbleChatWidget on which all message items have a bubble-like background-image.I thought I could achieve my goal with QTextEidt ,but I don't know how to give 'QTextFrame' or QTextBlock a background-image. So my question is that how to give QTextFrame or QTextBlock a background-image in QTextEdit ?If QTextEdit can't satisfy my demands, how to achieve my goal with other Qt techniques ? The BubbleChatWidget may contains clickable texts or pictures.And you can't forget the fact that the BubbleChatWidget may contains thousands of items

How to change current line format in QTextEdit without selection?

余生长醉 提交于 2019-12-04 04:28:33
问题 there! I want to find out how to change current line format in QTextEdit? In the document I read that "Formatting can be applied to the current text document using the setCharFormat(), mergeCharFormat(), setBlockFormat() and mergeBlockFormat() functions. If the cursor has no selection, current block format will be changed." But in my application, the current block in which cursor is couldn't be changed. May I miss something? Then how could I change current block format which has no selection?

Remove a line/block from QTextEdit

旧时模样 提交于 2019-12-04 03:26:22
问题 I'm struggling with block/line removal from QTextEdit . Code below should(?) work but it ends up in infinite loop for some unknown to me reason. I have a suspicion that next() and previous() are not welcome if QTextDocument is being edited. QTextBlock block = document()->begin(); while (block.isValid()) { if (to_do_or_not_to_do(block)) { QTextCursor cursor(block); cursor.select(QTextCursor::BlockUnderCursor); cursor.removeSelectedText(); } block = block.next(); } Iterating using QTextDocument

Pyqt: 'dynamically' append to qtextedit from function

那年仲夏 提交于 2019-12-03 21:05:47
问题 There is a button in my pyqt gui that when clicked runs a function that does some lengthy math calculations. Inside this function there were a lot of print statements like: print "finished calculating task1 going on to task2" So by using print statements like that i didn't need to have let's say a progressbar for example to indicate program progress. I added a QTextEdit widget in my gui and replaced all print statements in that function with: MyTextEdit.append('message') where MyTextEdit is a

How to set number of lines for an QTextEdit?

让人想犯罪 __ 提交于 2019-12-03 12:27:38
问题 I use a QTextEdit for some inputs. But I want to adjust the height of the box. Can I set the height based on the number of lines I want to have visible at a time? 回答1: If you use QPlainTextEdit , something like this should do the trick: void SetHeight (QPlainTextEdit* edit, int nRows) { QFontMetrics m (edit -> font()) ; int RowHeight = m.lineSpacing() ; edit -> setFixedHeight (nRows * RowHeight) ; } You might want to add two or three pixels as margin; experiment will tell. 回答2: Improving the

qtextedit - resize to fit

感情迁移 提交于 2019-12-03 11:07:29
I have a QTextEdit which act as "displayer" (editable to false). The text it displays is wordwrapped. Now I do wish to set the height of this textbox so that the text fits exactly (while also respecting a maximum height). Basically the widget (in the same vertical layout) below the layout should get as much space as possible. How can this be achieved most easily? Tiberius I found a pretty stable, easy solution using QFontMetrics ! from PyQt4 import QtGui text = ("The answer is QFontMetrics\n." "\n" "The layout system messes with the width that QTextEdit thinks it\n" "needs to be. Instead, let