1- If i cut text on QTextEdit subclass ...
QClipboard *netag = QApplication::clipboard();
QString textclip = netag->text(QClipboard::Selection);
QClipboard cant not read null string .... why?
2- If i take text from TextEdit::keyPressEvent(QKeyEvent *e)
QTextCursor tabact = textCursor();
QString actual = tabact.selectedText();
can read is ok but on console newline ("\n") are on unknow char (?) and
QStringList line = actual.split("\n"); can not split . why? only one line result if select 2 or more line...
void TextEdit
::IndentText(const QString text ,
int x
) {
for (int i = 0; i < line.size(); ++i) {
newline.append(onel);
}
qDebug() << "### line!!! " << line.size(); /* not correct */
const QString reformat
= newline.
join(Nline
);
netag->clear();
netag->setText(reformat);
paste();
}
{
if (e->key() == Qt::Key_Tab) {
int stabstart = tabact.selectionStart();
int stabstop = tabact.selectionEnd();
const QString actual
= tabact.
selectedText();
if (actual.size() > 3) {
IndentText(actual,1);
cut();
qDebug() << "### stabstart " << stabstart;
qDebug() << "### stabstop " << stabstart;
return;
}
}
void TextEdit::IndentText(const QString text , int x )
{
const QChar Nline('\n');
QClipboard *netag = QApplication::clipboard();
QString textclip = netag->text(QClipboard::Selection);
QStringList line = textclip.split(Nline);
QStringList newline;
for (int i = 0; i < line.size(); ++i) {
QString onel = QString("\t%1").arg(line.at(i));
newline.append(onel);
}
qDebug() << "### line!!! " << line.size(); /* not correct */
const QString reformat = newline.join(Nline);
netag->clear();
netag->setText(reformat);
paste();
}
void TextEdit::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Tab) {
QTextCursor tabact = textCursor();
int stabstart = tabact.selectionStart();
int stabstop = tabact.selectionEnd();
const QString actual = tabact.selectedText();
if (actual.size() > 3) {
IndentText(actual,1);
cut();
qDebug() << "### stabstart " << stabstart;
qDebug() << "### stabstop " << stabstart;
return;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks