回答編集履歴

4

v

2019/10/17 11:35

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -138,6 +138,8 @@
138
138
 
139
139
  print(obj.objectName())
140
140
 
141
+ # フォーカスされた lineedit を記録しておく。
142
+
141
143
  self.SecondWindow.set_lineedit(obj)
142
144
 
143
145
  self.SecondWindow.show()
@@ -178,8 +180,6 @@
178
180
 
179
181
  def on_button1_clicked(self):
180
182
 
181
- # self.parent() で親オブジェクト取得
182
-
183
183
  self.lineEdit.setText("1番のボタンが押された。")
184
184
 
185
185
 

3

d

2019/10/17 11:35

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -138,6 +138,8 @@
138
138
 
139
139
  print(obj.objectName())
140
140
 
141
+ self.SecondWindow.set_lineedit(obj)
142
+
141
143
  self.SecondWindow.show()
142
144
 
143
145
 
@@ -156,6 +158,10 @@
156
158
 
157
159
  uic.loadUi("secondwindow.ui", self)
158
160
 
161
+ self.lineEdit = None
162
+
163
+
164
+
159
165
  # pushButton1 の clicked シグナルを on_button1_clicked スロットに接続
160
166
 
161
167
  self.pushButton1.clicked.connect(self.on_button1_clicked)
@@ -174,19 +180,25 @@
174
180
 
175
181
  # self.parent() で親オブジェクト取得
176
182
 
177
- self.parent().lineEdit1.setText("1番のボタンが押された。")
183
+ self.lineEdit.setText("1番のボタンが押された。")
178
184
 
179
185
 
180
186
 
181
187
  def on_button2_clicked(self):
182
188
 
183
- self.parent().lineEdit2.setText("2番のボタンが押された。")
189
+ self.lineEdit.setText("2番のボタンが押された。")
184
190
 
185
191
 
186
192
 
187
193
  def on_button3_clicked(self):
188
194
 
189
- self.parent().lineEdit3.setText("3番のボタンが押された。")
195
+ self.lineEdit.setText("3番のボタンが押された。")
196
+
197
+
198
+
199
+ def set_lineedit(self, lineEdit):
200
+
201
+ self.lineEdit = lineEdit
190
202
 
191
203
 
192
204
 

2

d

2019/10/17 11:31

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -116,11 +116,15 @@
116
116
 
117
117
  self.lineEdit3.installEventFilter(self)
118
118
 
119
+
120
+
121
+ # 表示するまで、windows のジオメトリが確定しないため、ここで表示する。
122
+
119
123
  self.show()
120
124
 
121
125
 
122
126
 
123
- # メインウィンドウのに表示
127
+ # メインウィンドウの右隣 Second を表示
124
128
 
125
129
  self.SecondWindow = Second(self)
126
130
 
@@ -142,14 +146,6 @@
142
146
 
143
147
 
144
148
 
145
- def on_procStart(self, param):
146
-
147
- # クリックされた lineEdit に子画面から受け取った値をセットしたいです。
148
-
149
- self.lineEdit1.setText(param)
150
-
151
-
152
-
153
149
 
154
150
 
155
151
  class Second(QDialog):
@@ -160,16 +156,24 @@
160
156
 
161
157
  uic.loadUi("secondwindow.ui", self)
162
158
 
159
+ # pushButton1 の clicked シグナルを on_button1_clicked スロットに接続
160
+
163
161
  self.pushButton1.clicked.connect(self.on_button1_clicked)
164
162
 
163
+ # pushButton2 の clicked シグナルを on_button2_clicked スロットに接続
164
+
165
165
  self.pushButton2.clicked.connect(self.on_button2_clicked)
166
166
 
167
+ # pushButton3 の clicked シグナルを on_button3_clicked スロットに接続
168
+
167
169
  self.pushButton3.clicked.connect(self.on_button3_clicked)
168
170
 
169
171
 
170
172
 
171
173
  def on_button1_clicked(self):
172
174
 
175
+ # self.parent() で親オブジェクト取得
176
+
173
177
  self.parent().lineEdit1.setText("1番のボタンが押された。")
174
178
 
175
179
 

1

d

2019/10/17 07:27

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  シグナルスロットをお使いください。
10
10
 
11
- ボタンが押されたときに呼び出す関数はすでに設定できているようなので、あとは `self.parent()` で親クラスのオブジェクトを取得して、lineEdit1, 2, 3 に setText で直接設定してください。
11
+ ボタンが押されたときに呼び出す関数はすでに設定できているようなので、あとは `self.parent()` で親クラスのオブジェクトを取得して、lineEdit1, lineEdit2, lineEdit3 に setText で直接設定してください。
12
12
 
13
13
 
14
14