/* * 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(); 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 && 0pos().x()+8); this->setTextCursor(cursorForPosition(currentPt)); return; } } if(e->button() == Qt::LeftButton) { QWSServer::sendKeyEvent(0,Qt::Key_Left1,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_Left,Qt::NoModifier,true,false); //向系统发送键盘事件 QWSServer::sendKeyEvent(0,Qt::Key_Right1,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_Right,Qt::NoModifier,true,false); //setCursor(); //QTextCursor textCursor = this->textCursor(); //textCursor.clearSelection(); //textCursor.setPosition(e->x()); //textCursor.setBlockFormat(textBlockFormat); //this->setTextCursor(textCursor); } // if(e->button() == Qt::RightButton) // { // e->ignore(); // } // else { QTextEdit::mousePressEvent(e); } } //bool MyTextEdit::qwsEvent ( QWSEvent * event ){ //} //void MyTextEdit::mouseMoveEvent ( QMouseEvent * e ){ // e->ignore(); //} // //void MyTextEdit::changeEvent ( QEvent * event ){ // if(event->type()==QEvent::FontChange) // { // } // QTextEdit::changeEvent(event); //} //void MyTextEdit::mouseReleaseEvent(QMouseEvent * e) //{ // QTextCursor textCursor = this->textCursor(); // textCursor.clearSelection(); // QTextEdit::mouseReleaseEvent(e); //}