Hi All,
How to get the heightForWidth for a widget. I always get the value as -1. Is there anything I'm missing?
The following is my code.
TextEdit
::TextEdit(QWidget *parent
){
setGeometry( geometry().x(), geometry().y(), parent->width(), 20 );
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
sizePolicy.setHeightForWidth(true);
setSizePolicy(sizePolicy);
connect( this, SIGNAL( textChanged() ), this, SLOT( slotTextChanged() ) );
setMouseTracking( true );
}
TextEdit::~TextEdit()
{}
void TextEdit::slotTextChanged()
{
qDebug() << heightForWidth ( width() );
}
TextEdit::TextEdit(QWidget *parent)
:QTextEdit(parent)
{
setGeometry( geometry().x(), geometry().y(), parent->width(), 20 );
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
sizePolicy.setHeightForWidth(true);
setSizePolicy(sizePolicy);
connect( this, SIGNAL( textChanged() ), this, SLOT( slotTextChanged() ) );
setMouseTracking( true );
}
TextEdit::~TextEdit()
{}
void TextEdit::slotTextChanged()
{
qDebug() << heightForWidth ( width() );
}
To copy to clipboard, switch view to plain text mode
int main(int argc, char *argv[])
{
widget.resize( 400, 20 );
TextEdit* textEdit = new TextEdit( &widget );
widget.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget widget;
widget.resize( 400, 20 );
TextEdit* textEdit = new TextEdit( &widget );
widget.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Thanks in advance.
Bookmarks