[Qt-interest] qtoolbar
Pradeep K Vijayan
pradeep.vijayan at gmail.com
Fri Sep 24 14:54:14 CEST 2010
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
>
>
>
>
>
More information about the Qt-interest-old
mailing list