PDA

View Full Version : QTextEdit, sizeHint, QWidget



TheKedge
2nd February 2007, 17:15
I've got a QTextEdit inside a sub-class of QWidget. I just want to display some simple (rich) text. I'd like the QTextEdit to scale to it's contents and the window around it around it to scale too.



class MyThing: public QWidget
{
MyThing(QWidget* parent = 0);
//...etc

private:
QTextEdit* txtEdit;
}
//the constructor
MyThing(QWidget *parent): QWidget (parent)
{
txtEdit= new QTextEdit(this) ;
QWidget::setFixedSize(txtEdit->sizeHint());
}

I think the problem is that txtEdit->sizeHint() is not influenced by the (small) amount of text in the QTextEdit. Is there any way of telling QTextEdit to occupy the minimum space possible for the given text formatting?

thanks
K

jpn
3rd February 2007, 09:25
Maybe QTextDocument::size() is what you are looking for? QLabel is also one possibility in case the text is just shown and not meant to be modified.