[Qt-interest] qlineedit sizehint question.
phil prentice
philp.cheer at talktalk.net
Wed Jan 27 19:02:46 CET 2010
Hi
I'm slowly porting over a Motif X11 application to QT. The old application
used to define lots of line edit windows of a fixed size. So if a width was
set
to 6 characters then the line edit window would be set to 6 characters length.
So I am trying to use sizeHint() to achieve the same result. e.g.
QSize CateQLineEdit::sizeHint() const
{
struct generic_field *lineedit;
QSize size;
size = QLineEdit::sizeHint();
if((lineedit = generic_field()) != NULL)
{
/* lineedit->local.cef.width = 6 */
size.setWidth(fontMetrics().maxWidth() * lineedit->local.cef.width
+ PADDING);
}
return size;
}
This kind of works if I set PADDING to 8 pixels.
Not ideal though, because I really need to use qwidget_p.h leftmargin &
rightmargin values which is part of the Pimpl implementation. There is no
easy way at getting at these variables. I tried ....
QSize CateQLineEdit::sizeHint() const
{
struct generic_field *lineedit;
QSize size;
size = QLineEdit::sizeHint();
if((lineedit = generic_field()) != NULL)
{
QLineEditPrivate *const d = reinterpret_cast<QLineEditPrivate *>(d_ptr);
size.setWidth(fontMetrics().maxWidth() * lineedit->local.cef.width +
d->leftmargin + d->rightmargin);
}
return size;
}
but of course the include files stop me when I try and do the build. I know
that it is unsupported to access these variables, but is these any clever way
of me being able to do this?
I'm using this as more of a fun/learning project and was just wondering what
method would be best to overcome this problem. One way might be to simply
add two new member functions to the QLineEdit implementation to return
leftmargin & rightmargin and re-build it, but that does not seem very clever
either (I would always have to use that version of QT; not a problem for me,
but again there must be a better way?)
Thanks for your help
More information about the Qt-interest-old
mailing list