2012-07-17 20 views
9

Cómo puedo establecer el ancho visible de QLineEdit con Qt 4.8.1 y más. El ejemplo sería establecer el ancho visible a algún tamaño de píxel o ancho de carácter. Solo deseo usar C++, no QML.QLineEdit ancho visible Configuración?

Mi pensamiento está en la dirección de este bloque:

QHBoxLayout *nameRow = new QHBoxLayout; 

QLineEdit *firstNameText = new QLineEdit, 
      *middleIntText = new QLineEdit, 
      *lastNameText = new QLineEdit; 
//Whatever method is needed here to edit visible width 
//firstNameText->??? 
//middleIntText->??? 
//lastNameText->??? 

nameRow->addWidget(firstNameText); 
nameRow->addWidget(middleIntText); 
nameRow->addWidget(lastNameText); 

layout->addLayout(nameRow); 

QWidget window; 
window.setLayout(layout); 
window.show(); 

respuesta Actualización: (o ver más abajo)

firstNameText->setMaximumWidth(100); 
firstNameText->setFixedWidth(120); 

middleIntText->setMaximumWidth(50); 
middleIntText->setFixedWidth(60); 

lastNameText->setMaximumWidth(100); 
lastNameText->setFixedWidth(120); 
+0

¿Estás diciendo que quieres que el área de contenido recorta a un cierto tamaño independientemente del ancho real del widget? ¿Aún desea permitir el ancho de cualquier tamaño de datos y widgets pero no el ancho del área de contenido? – jdi

Respuesta

9
firstNameText->setMaximumWidth(100); 
firstNameText->setFixedWidth(120); 

Usted puede utilizar thse dos funciones y ellos ajustarán el ancho en consecuencia.

+0

@Brandon Clark: he editado la respuesta. En el futuro, puede simplemente sugerir una edición a una publicación para formatearla, y se colocará en una cola de revisión para su aprobación :) – BoltClock

+0

user1529294, bienvenido al sitio - consulte http://stackoverflow.com/editing- ayuda a aprender a formatear tus publicaciones. – BoltClock

Cuestiones relacionadas