PDA

View Full Version : QPlainTextEdit: find first visible text block?



tuli
27th July 2014, 06:31
I want to get the first visible textblock in the textedit. There is a function for that, but it is protected:

http://qt-project.org/doc/qt-4.8/qplaintextedit.html#firstVisibleBlock

why is it protected? How do i do this?

stampede
27th July 2014, 10:26
How do i do this?
you can access it in a subclass:


class MyPlainTextEdit : public QPlainTextEdit{
//constructors, Q_OBJECT macro etc...
//...
public:
QTextBlock firstBlock() const{
return QPlainTextEdit::firstVisibleBlock();
}
};

tuli
27th July 2014, 10:43
yes, this is what i do now. thank you. But it is a little wired, why is it protected? Maybe they do not want me to use that function?

stampede
27th July 2014, 10:50
Maybe they do not want me to use that function?
I don't think so, it is "protected" not "private" after all. They just didn't want it to be a part of the public interface, I'm not very well acquainted with text editing interfaces in Qt but I guess they had some reasons :)