/* * MyTextEdit.cpp * * Created on: Aug 7, 2013 * Author: yiyu * QQ:1036184468 * Descriptoin: */ #include #include "SysPara.h" #include #include #include #include #include #include #include MyTextEdit::MyTextEdit(QWidget *parent):QTextEdit(parent){ this->document()->setDocumentMargin(0); // QTextDocument *doc = this->document(); //获取文档对象 // QTextFrame *rootFrame = doc->rootFrame(); //获取根框架 // QTextFrameFormat frameFormat; //创建框架格式 // frameFormat.setBorderBrush(Qt::red); //设置边界颜色 // frameFormat.setBorder(0); //设置边界宽度 // rootFrame->setFrameFormat(frameFormat); //给框架使用格式 //this->setTextInteractionFlags(Qt::TextEditable);//不能选中 this->setLineWrapMode(QTextEdit::NoWrap); for(QTextBlock textBlock = this->document()->begin(); textBlock != this->document()->end(); textBlock = textBlock.next()){ QTextBlockFormat textBlockFormat = textBlock.blockFormat(); textBlockFormat.setBottomMargin(0); QTextCursor textCursor = this->textCursor(); textCursor.setBlockFormat(textBlockFormat); this->setTextCursor(textCursor); } } void MyTextEdit::dragEnterEvent ( QDragEnterEvent * e ){ e->ignore(); } void MyTextEdit::dragLeaveEvent ( QDragLeaveEvent * e ){ e->ignore(); } void MyTextEdit::dragMoveEvent ( QDragMoveEvent * e ){ e->ignore(); } void MyTextEdit::mouseDoubleClickEvent ( QMouseEvent * e ){ e->ignore(); } void MyTextEdit::mousePressEvent(QMouseEvent * e) { //获取点击的下标 // qDebug() << e->x() << ":" << e->y(); quint16 count=0; if(this->toPlainText().length()>1 && cursorForPosition(e->pos()).atEnd()) { int textHeight=this->height(); QPoint currentPt=e->pos(); QTextCursor textCursor=cursorForPosition(currentPt); while(textCursor.atEnd() && 0<--textHeight && 0width(); currentPt.setX(e->pos().x()); currentPt.setY(currentPt.y()-5); textCursor=cursorForPosition(currentPt); while(textCursor.atEnd() && 0<--textWidth && 0