質問するログイン新規登録

回答編集履歴

2

コメント対応

2019/09/23 03:35

投稿

nomuken
nomuken

スコア1627

answer CHANGED
@@ -21,4 +21,39 @@
21
21
  strSex = "未選択"
22
22
 
23
23
  QMessageBox.about(self, "Title", '名前: ' + self.textname.text() + '\nTEL: ' + self.texttel.text() + '\n性別: ' + strSex)
24
- ```
24
+ ```
25
+
26
+ ---
27
+ > ①ラジオボタンの値の取得
28
+
29
+ ラジオボタンを取り扱う場合はまず「グループ化」が必要です。(ラジオボタンはそのグループの中で一つだけ選択可能となります。)
30
+
31
+ importにQButtonGroupを追加
32
+ ```Python
33
+ from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QGridLayout, QPushButton, QLineEdit, QMessageBox, QCheckBox, QRadioButton, QButtonGroup
34
+ ```
35
+
36
+ ラジオボタン作成後にグループ化。同時にボタンにIDを振ります。今回の場合は0=A, 1=B, 2=O, 3=AB
37
+ ```Python
38
+ self.groupBloodType = QButtonGroup()
39
+ self.groupBloodType.addButton(self.radioA, 0)
40
+ self.groupBloodType.addButton(self.radioB, 1)
41
+ self.groupBloodType.addButton(self.radioO, 2)
42
+ self.groupBloodType.addButton(self.radioAB, 3)
43
+ ```
44
+
45
+ self.groupBloodType.checkedId()でグループの中で選択されているボタンのIDをとれます。
46
+ ```Python
47
+ if self.groupBloodType.checkedId() < 0:
48
+ strBloodType = "未選択"
49
+ else:
50
+ strBloodType = [ 'A', 'B', 'O', 'AB' ][self.groupBloodType.checkedId()]
51
+ ```
52
+
53
+ > ②Qtページにて、どのようにして該当のものを探し出しているか
54
+
55
+ 基本は
56
+ [Qt 5.13 Documentationのページ](https://doc.qt.io/qt-5/index.html)で右上の検索欄からクラス名で検索します。
57
+
58
+ あとはやりたいことから適当に単語を抜き出して" PyQt5 [抜き出した単語]"でググります。
59
+ 必要であればすべての単語を英語にして日本語限定を外して検索します。

1

実装例追加

2019/09/23 03:35

投稿

nomuken
nomuken

スコア1627

answer CHANGED
@@ -3,4 +3,22 @@
3
3
  ```
4
4
  if self.checkman.checkState():
5
5
  ```
6
- みたいな感じです。
6
+ みたいな感じです。
7
+
8
+ ---
9
+ > 申し訳ありませんが、具体的にどのようにコードを書けば良いか教えて頂けますでしょうか??
10
+
11
+ こんな感じでしょうか
12
+ ```Python
13
+ def buttonClicked(self):
14
+ if self.checkman.checkState() and self.checkwoman.checkState():
15
+ strSex = "なぞ"
16
+ elif self.checkman.checkState():
17
+ strSex = "男性"
18
+ elif self.checkwoman.checkState():
19
+ strSex = "女性"
20
+ else:
21
+ strSex = "未選択"
22
+
23
+ QMessageBox.about(self, "Title", '名前: ' + self.textname.text() + '\nTEL: ' + self.texttel.text() + '\n性別: ' + strSex)
24
+ ```