2012-07-17 27 views
9

QLineEditの可視幅をQt 4.8.1以上に設定するにはどうすればいいですか?例としては、可視の幅をピクセルサイズまたは文字幅に設定することです。 QMLではなくC++のみを使用したいと考えています。QLineEdit可視幅の設定?

私の考えは、このブロックの方向にあります。

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(); 

回答アップデート:または下記参照)

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

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

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

ウィジェットの実際の幅に関係なく、コンテンツ領域を特定のサイズに切り詰めたいとお考えですか?それでもデータサイズとウィジェットの幅は許可したいがコンテンツ領域の幅は許可したくない? – jdi

答えて

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

あなたはthse二つの機能を使用することができますし、それに応じて幅を調整します。

+0

@Brandon Clark:答えを編集しました。将来的には、投稿を編集してフォーマットすることができます。承認のためにレビューキューに入れられます:) – BoltClock

+0

user1529294、サイトへようこそ - http://stackoverflow.com/editing-あなたの投稿のフォーマット方法を学ぶのに役立ちます。 – BoltClock

関連する問題