Добавлю код...
class TextEdit:public QPlainTextEdit{
Q_OBJECT
public:
TextEdit(QWidget* parent);
private:
virtual bool event(QEvent*);
virtual void mouseMoveEvent ( QMouseEvent * e );
virtual void mousePressEvent ( QMouseEvent * e );
virtual void mouseReleaseEvent ( QMouseEvent * e );
private:
QPoint _pnt;
int _dh;
int _dw;
};
TextEdit::TextEdit(QWidget* parent)
:QPlainTextEdit(parent)
{
QFontMetrics fm(font());
_dh = fm.height();
_dw = fm.width(" ");
setFrameShape(QFrame::NoFrame);
setReadOnly(true);
setContextMenuPolicy(Qt::NoContextMenu);
}
void TextEdit::mouseMoveEvent ( QMouseEvent * e )
{
if(!_pnt.isNull()){
QScrollBar* pV = verticalScrollBar();
QScrollBar* pH = horizontalScrollBar();
QPoint pnt(e->pos());
int dx = _pnt.x()-pnt.x();
int dy = _pnt.y()-pnt.y();
if(pV->isVisible()){
if(int v = dy / pV->singleStep() / _dh){
v += pV->value();
if(v<pV->minimum()){
v = pV->minimum();
}else if(v>pV->maximum()){
v = pV->maximum();
}
pV->setValue(v);
}else{
pnt.setY(_pnt.y());
}
}
if(pH->isVisible()){
if(int v = dy / pH->singleStep() / _dw){
v += pH->value();
if(v<pH->minimum()){
v = pH->minimum();
}else if(v>pH->maximum()){
v = pV->maximum();
}
pH->setValue(v);
}else{
pnt.setX(_pnt.x());
}
}
_pnt = pnt;
}
}
void TextEdit::mousePressEvent ( QMouseEvent * e )
{
_pnt = e->pos();
}
void TextEdit::mouseReleaseEvent ( QMouseEvent * e )
{
_pnt = QPoint();
}
bool TextEdit::event(QEvent* e)
{
int type = e->type();
switch(type){
case QEvent::Enter:{
_pnt = QPoint();
}break;
case QEvent::Leave:{
_pnt = QPoint();
}break;
}
return QPlainTextEdit::event(e);
}