[Qt-interest] qtoolbar
phil prentice
philp.cheer at talktalk.net
Fri Sep 24 21:12:33 CEST 2010
HI Pradeep
Sorry for the delay in getting back to you.
And thankyou for your example. I am using Qt version 4.2.1 and yes your
example does work for me. I will update your example to follow what my code
does in my app and see if I can understand why my app does not work in the
same way.
I will let you know how I get on.
Thanks again
Phil Prentice
On Friday 24 September 2010 12:54, Pradeep K Vijayan wrote:
> Hi,
>
> The below code worked for me with Qt 4.6.3:
>
> #include <QApplication>
> #include <QMainWindow>
> #include <QLineEdit>
> #include <QToolBar>
> #include <QLabel>
>
> class MainWindow : public QMainWindow
> {
> public:
> MainWindow( QWidget* parent = NULL )
>
> : QMainWindow( parent )
>
> {
> m_networkLineEdit = new QLineEdit( this );
>
> // Set attributes.
> m_networkLineEdit->setReadOnly(true);
> m_networkLineEdit->setMaxLength(17); /* Allow max of 17
> characters. */
>
> QToolBar* m_networkIdToolBar = addToolBar( "" );
> m_networkIdToolBar->addWidget(new QLabel( "Blah:" ));
> m_networkIdToolBar->addWidget(m_networkLineEdit);
> m_networkIdToolBar->addWidget(new QLabel( "The end!" ));
> }
>
> void foo()
> {
> m_networkLineEdit->setFixedWidth( 17 *
> m_networkLineEdit->fontMetrics().maxWidth() + 20);
> }
>
> private:
> QLineEdit* m_networkLineEdit;
> };
>
> int main( int argc, char* argv[] )
> {
> QApplication app( argc, argv );
> MainWindow mw;
> mw.resize( 600, 200 );
> mw.show();
> mw.foo();
> return app.exec();
> }
>
> Regards,
> Pradeep K Vijayan
>
> On 24/09/2010 13:03, phil prentice wrote:
> > Hi everyone
> >
> > I have a tool bar at the top of my window which has a QLineEdit box
> > inserted into it. i.e.
> >
> > m_networkLineEdit = new QLineEdit();
> > // Set attributes.
> > m_networkLineEdit->setReadOnly(true);
> > m_networkLineEdit->setMaxLength(17); /* Allow max of 17 characters. */
> >
> > m_networkIdToolBar = addToolBar("");
> > m_networkIdToolBar->addWidget(m_networkLabel);
> > m_networkIdToolBar->addWidget(m_networkLineEdit);
> >
> > A number of other actions& widgets are also in the toolbar.
> >
> > I've also got separators in place as well.
> >
> > My question is what determines the size of the lineedit box in the
> > toolbar. I've tryed various things like
> >
> > m_networkLineEdit->setFixedWidth(
> > 17 * m_networkLineEdit->fontMetrics().maxWidth()+20);
> >
> > to increase its size with no success.
> >
> > I've tryed increasing the 17 characters to 30 odd as well and again no
> > success.
> >
> > I know that I can drag the separator to make it bigger, but I would
> > like it to display all 17 characters.
> >
> > To be honest I think I have a fonts problem of some sort, because when
> > I use wider screens, the same number of characters no longer fit in the
> > widgets; but thats another question.
> >
> > Thanks for your help
> > Phil
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list