[Qt-interest] qtoolbar
phil prentice
philp.cheer at talktalk.net
Mon Sep 27 14:28:53 CEST 2010
Hi
Last week I showed that I had a problem fixing the size of a lineEdit box
inside the toolbar and Pradeep very kindly demonstrated the sort of thing
that I am trying to do which works fine. His example also worked for me, so
I lifted out the code in my application that has the problem. Basically it
does not correctly show all the text inside a lineedit box even though I am
trying to fix its size?? The version of QT that I am using is 4.2.1
Any comments most welcome....
Thanks
Phil
The code follows:-
#include <QApplication>
#include <QtGui>
class MainWindow : public QMainWindow
{
public:
MainWindow( QWidget* parent = NULL )
: QMainWindow( parent )
{
m_networkLabel = new QLabel("Network ");
m_networkLineEdit = new QLineEdit();
// Set attributes.
m_networkLineEdit->setReadOnly(true);
m_networkLineEdit->setMaxLength(17); /* Allow max of 17 characters. */
m_frequencyLineEdit = new QLineEdit();
// Set attributes.
m_frequencyLineEdit->setReadOnly(true);
m_frequencyLineEdit->setMaxLength(6); /* Allow max of 6 characters. */
m_frequencyLineEdit->setFixedWidth(
m_frequencyLineEdit->fontMetrics().width("1500Hz") +20); // 1500Hz
m_voltMinus = new QAction(this);
//m_voltMinus->setIcon(QIcon(":/resources/images/V-.png"));
m_voltMinus->setIcon(QIcon());
m_voltPlus = new QAction(this);
m_voltPlus->setIcon(QIcon());
m_freqMinus = new QAction(this);
m_freqMinus->setIcon(QIcon());
m_freqPlus = new QAction(this);
m_freqPlus->setIcon(QIcon());
m_pulseVoltMinus = new QAction(this);
m_pulseVoltMinus->setIcon(QIcon());
m_pulseVoltPlus = new QAction(this);
m_pulseVoltPlus->setIcon(QIcon());
m_pulseWidthMinus = new QAction(this);
m_pulseWidthMinus->setIcon(QIcon());
m_pulseWidthPlus = new QAction(this);
m_pulseWidthPlus->setIcon(QIcon());
m_pcToleranceMinus10 = new QAction(this);
m_pcToleranceMinus10->setIcon(QIcon());
m_pcToleranceMinus1 = new QAction(this);
m_pcToleranceMinus1->setIcon(QIcon());
m_pcToleranceEnable = new QAction(this);
m_pcToleranceEnable->setIcon(QIcon());
m_pcTolerancePlus1 = new QAction(this);
m_pcTolerancePlus1->setIcon(QIcon());
m_pcTolerancePlus10 = new QAction(this);
m_pcTolerancePlus10->setIcon(QIcon());
QSize size(32,32);
m_networkIdToolBar = addToolBar("");
m_networkIdToolBar->addWidget(m_networkLabel);
m_networkIdToolBar->addWidget(m_networkLineEdit);
m_saveAction = new QAction("&Save", this);
m_saveAction->setIcon(QIcon());
m_saveToolBar = addToolBar("");
m_voltFreqToolBar = addToolBar("");
m_voltFreqToolBar->addAction(m_voltMinus);
m_voltFreqToolBar->addAction(m_voltPlus);
m_voltFreqToolBar->addSeparator();
m_voltFreqToolBar->addAction(m_freqMinus);
m_voltFreqToolBar->addAction(m_freqPlus);
m_voltFreqToolBar->setIconSize(size);
m_pulseToolBar = addToolBar("");
m_pulseToolBar->addAction(m_pulseVoltMinus);
m_pulseToolBar->addAction(m_pulseVoltPlus);
m_pulseToolBar->addSeparator();
m_pulseToolBar->addAction(m_pulseWidthMinus);
m_pulseToolBar->addAction(m_pulseWidthPlus);
m_pulseToolBar->setIconSize(size);
m_toleranceToolBar = addToolBar("");
m_toleranceToolBar->addAction(m_pcToleranceMinus10);
m_toleranceToolBar->addAction(m_pcToleranceMinus1);
m_toleranceToolBar->addSeparator();
m_toleranceToolBar->addAction(m_pcToleranceEnable);
m_toleranceToolBar->addSeparator();
m_toleranceToolBar->addAction(m_pcTolerancePlus1);
m_toleranceToolBar->addAction(m_pcTolerancePlus10);
m_toleranceToolBar->setIconSize(size);
m_frequencyToolBar = addToolBar("");
m_frequencyToolBar->addWidget(m_frequencyLineEdit);
}
void foo()
{
m_networkLineEdit->setFixedWidth( 17 *
m_networkLineEdit->fontMetrics().maxWidth() + 20);
m_networkLineEdit->setText("ZZZZZZZZZZZZZZZZZ");
}
private:
QToolBar *m_frequencyToolBar;
QToolBar *m_networkIdToolBar;
QToolBar *m_saveToolBar;
QToolBar *m_voltFreqToolBar;
QToolBar *m_pulseToolBar;
QToolBar *m_toleranceToolBar;
QAction *m_saveAction;
QAction *m_voltMinus;
QAction *m_voltPlus;
QAction *m_freqMinus;
QAction *m_freqPlus;
QAction *m_pulseVoltMinus;
QAction *m_pulseVoltPlus;
QAction *m_pulseVoltPlus;
QAction *m_pulseWidthMinus;
QAction *m_pulseWidthPlus;
QAction *m_pcToleranceMinus10;
QAction *m_pcToleranceMinus1;
QAction *m_pcToleranceEnable;
QAction *m_pcTolerancePlus1;
QAction *m_pcTolerancePlus10;
QLineEdit* m_networkLineEdit;
QLabel *m_networkLabel;
QLineEdit *m_frequencyLineEdit;
};
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
MainWindow mw;
mw.resize(QSize(1260, 560));
mw.show();
mw.foo();
return app.exec();
}
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