Qt logo

QLineDialog Class Reference


A convenience dialog to get a simple input from the user More...

#include <qlinedialog.h>

Inherits QDialog.

List of all member functions.

Public Members

Static Public Members


Detailed Description

A convenience dialog to get a simple input from the user

The QLineDialog is a simple dialog which can be used if you need a simple input from the user. This can be text, a number or an item from a list. Also a label has to be set to tell the user what he/she should input.

To be able to get different types of inputs, you can set the input type of the dialog with setType().

To e.g. get a textual input from the user you can use one of the static methods like this:

  bool ok = FALSE;
  QString text = QLineDialog::getText( tr( "Please enter your name" ), QString::null, &ok, this );
  if ( ok && !text.isEmpty() )
      ;// user entered something and pressed ok
  else
      ;// user entered nothing or pressed cancel

There are more static convenience methods!

See also: getText(), getInteger(), getDouble() and getItem().


Member Type Documentation

QLineDialog::Type

This enum type specifies the type of the dialog (which kind of input can be done):


Member Function Documentation

QLineDialog::QLineDialog ( const QString & label, QWidget * parent = 0, const char * name = 0, bool modal = TRUE, Type type = LineEdit )

Constructs the dialog. label is the text which is shown to the user (it should mention to the user what he/she should input), parent the parent widget of the dialog, name the name of it and if you set modal to TRUE, the dialog pops up modally, else it pops up modeless. With type you specify the type of the dialog.

See also: getText(), getInteger(), getDouble() and getItem().

QLineDialog::~QLineDialog ()

Destructor.

QComboBox * QLineDialog::comboBox () const

Returns the combobox, which is used in the ComboBox mode.

QComboBox * QLineDialog::editableComboBox () const

Returns the combobox, which is used in the EditableComboBox mode.

double QLineDialog::getDouble ( const QString & label, double num = 0, double from = -2147483647, double to = 2147483647, int decimals = 1, bool * ok = 0, QWidget * parent = 0, const char * name = 0 ) [static]

Static convenience function to get a decimal input from the user. label is the text which is shown to the user (it should mention to the user what he/she should input), num the default decimal number which will be initially set to the line edit, from and to the range in which the entered number has to be, decimals the number of decimal which the number may have, ok a pointer to a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the user pressed cancel, parent the parent widget of the dialog and name the name of it. The dialogs pops up modally!

This method returns the number which has been entered by the user.

You will use this static method like this:

  bool ok = FALSE;
  double res = QLineDialog::getDouble( tr( "Please enter a decimal number" ), 33.7, 0, 1000, 2, &ok, this );
  if ( ok )
      ;// user entered something and pressed ok
  else
      ;// user pressed cancel

int QLineDialog::getInteger ( const QString & label, int num = 0, int from = -2147483647, int to = 2147483647, int step = 1, bool * ok = 0, QWidget * parent = 0, const char * name = 0 ) [static]

Static convenience function to get an integral input from the user. label is the text which is shown to the user (it should mention to the user what he/she should input), num the default number which will be initially set to the spinbox, from and to the range in which the entered number has to be, step the step in which the number can be increased/decreased by the spinbox, ok a pointer to a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the user pressed cancel, parent the parent widget of the dialog and name the name of it. The dialogs pops up modally!

This method returns the number which has been entered by the user.

You will use this static method like this:

  bool ok = FALSE;
  int res = QLineDialog::getInteger( tr( "Please enter a number" ), 22, 0, 1000, 2, &ok, this );
  if ( ok )
      ;// user entered something and pressed ok
  else
      ;// user pressed cancel

QString QLineDialog::getItem ( const QString & label, const QStringList & list, int current = 0, bool editable = TRUE, bool * ok = 0, QWidget * parent = 0, const char * name = 0 ) [static]

Static convenience function to let the user select an item from a string list. label is the text which is shown to the user (it should mention to the user what he/she should input), list the string list which is inserted into the combobox, current the nimber of the item which should be initially the current item, editable specifies if the combobox should be editable (if it is TRUE) or readonly (if editable is FALSE), ok a pointer to a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the user pressed cancel, parent the parent widget of the dialog and name the name of it. The dialogs pops up modally!

This method returns the text of the current item, or if editable was TRUE, the current text of the combobox.

You will use this static method like this:

  QStringList lst;
  lst << "First" << "Second" << "Third" << "Fourth" << "Fifth";
  bool ok = FALSE;
  QString res = QLineDialog::getItem( tr( "Please select an item" ), lst, 1, TRUE, &ok, this );
  if ( ok )
      ;// user selected an item and pressed ok
  else
      ;// user pressed cancel

QString QLineDialog::getText ( const QString & label, const QString & text = QString::null, bool * ok = 0, QWidget * parent = 0, const char * name = 0 ) [static]

Static convenience function to get a textual input from the user. label is the text which is shown to the user (it should mention to the user what he/she should input), text the default text which will be initially set to the line edit, ok a pointer to a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the user pressed cancel, parent the parent widget of the dialog and name the name of it. The dialogs pops up modally!

This method returns the text which has been entered in the line edit.

You will use this static method like this:

  bool ok = FALSE;
  QString text = QLineDialog::getText( tr( "Please enter your name" ), QString::null, &ok, this );
  if ( ok && !text.isEmpty() )
      ;// user entered something and pressed ok
  else
      ;// user entered nothing or pressed cancel

QLineEdit * QLineDialog::lineEdit () const

Returns the line edit, which is used in the LineEdit mode.

void QLineDialog::setType ( Type t )

Sets the input type of the dialog to t.

QSpinBox * QLineDialog::spinBox () const

Returns the spinbox, which is used in the SpinBox mode.

QLineDialog::Type QLineDialog::type() const

Returns the input type of the dialog.

See also: setType().


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-2000 Troll Tech, all rights reserved.


Copyright İ 2000 Troll TechTrademarks
Qt version 2.1.0 (pre-release)