PDA

View Full Version : QTextEdit fixed size with no scroll



mihnen
1st August 2012, 18:00
Is there anyway to completely disable the vertical scrolling of a QTextEdit? What I'm trying to do is have a wysiwyg editor to make labels and I need a fixed size text area that will stop accepting input when there is no room left. We are implementing auto sizing of the text and when the minimum text size is met and the user is out of space we want to stop accepting input. I can't seem to find a way to do this, you can disable scrollbars but the widget keeps scrolling. When I try to do the autosizing using the size of the rect it reports back the wrong size, what I really want is the viewable size of the rect.

sonulohani
3rd August 2012, 11:40
QAbstractScrollArea::setVerticalScrollBarPolicy() (http://doc.trolltech.com/4.3/qabstractscrollarea.html#verticalScrollBarPolicy-prop)
QAbstractScrollArea::setHorizontalScrollBarPolicy( )
(http://doc.trolltech.com/4.3/qabstractscrollarea.html#horizontalScrollBarPolicy-prop)

mihnen
8th August 2012, 00:30
well, that doesn't actually fix the size of the widget it just hides the scrollbars, so not much help. I have tried experimenting with QGraphicsTextItem and think I might be able to get that working by setting the QGraphicsScene rect to a fixed size QRect. Thanks anyways for your response.

thomas@itest
8th August 2012, 13:14
maybe you should look at QTextDocument :



void YourTextEdit::keyPressEvent(QKeyEvent *event)
{
if(document()->characterCount() > DEFINED_MAX_CHAR) return;
QTextEdit::keyPressEvent(event);
}


(not tested)

QTextDocument also has a size() method ...