質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
TableView

TableView(UITableView)とは、リスト形式で表示するコントロールで、ほとんどのアプリに使用されています。画面を「行」に分けて管理し、一般的には各行をタップした際に詳細画面に移動します。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

0回答

410閲覧

サブウインドウでGraphicsViewを使用する方法 PyQt5

goki_gottan

総合スコア168

TableView

TableView(UITableView)とは、リスト形式で表示するコントロールで、ほとんどのアプリに使用されています。画面を「行」に分けて管理し、一般的には各行をタップした際に詳細画面に移動します。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

1クリップ

投稿2022/07/11 10:41

Pythonで、TableViewを作成しており、ボタンを押すとサブウインドウが開かれる仕様を作っております。
ただのサブウインドウでしたら、「self.w1 = QDialog(parent)」で対応できるのですが、サブウインドウに「GraphicsView」を設けますと、
「self.w1 = QDialog(parent)」をどのように使用したら良いのか、うまく使用できないとサブウインドウの「GraphicsView」は一瞬立ち上がってすぐ落ちます。 コードは色々と省略しましたが、主要部分を残しました。

class TableView(QTableWidget): def __init__(self, data, *args): QTableWidget.__init__(self, *args) self.resizeRowsToContents() class basicWindow(QWidget): def __init__(self, parent=None): self.w = QDialog(parent) self.w.setWindowTitle('Basic Grid Layout') grid_layout = QGridLayout() self.w.setLayout(grid_layout) def clickCallback10(): ex2 = sWindow() ex2.show() g_1="" button_0 = QPushButton() button_0.clicked.connect(clickCallback10) button_0.setIcon(QtGui.QIcon(g_1)) grid_layout.addWidget(button_0, y, x) def show(self): self.w.exec_() class sWindow(QWidget): def __init__(self, parent=None): self.w1 = QDialog(parent) self.w1.setWindowTitle('Option') grid_layout = QGridLayout() self.w1.setLayout(grid_layout) def clickCallback22(): widget = QtWidgets.QWidget(None) leyout = QtWidgets.QVBoxLayout(widget) leyout.addWidget( QtWidgets.QLabel(widget) ) leyout.addWidget( GraphicsView(widget) ) widget.setLayout(leyout) widget.show() self.w1.button12 = QPushButton('', self.w1) self.w1.button12.clicked.connect(clickCallback22) def show(self): self.w1.exec_() class GraphicsView(QtWidgets.QGraphicsView): def __init__(self, parent=None): super(GraphicsView, self).__init__(parent) self.w2 = QDialog(parent) self.w2.setWindowTitle('Option') scene = QtWidgets.QGraphicsScene(self.w2) image = QtGui.QImage("") pixmap = QtGui.QPixmap.fromImage(image) scene.addPixmap(pixmap) scene.setBackgroundBrush(QtCore.Qt.gray) self.setScene(scene) self.w2._numScheduledScalings = 0 self.w2.label = self.parent().findChild(QtWidgets.QLabel) self.w2.coordinates = [] def wheelEvent(self, event): numDegrees = event.angleDelta().y() / 8 numSteps = numDegrees / 15 self.w2._numScheduledScalings += numSteps if self.w2._numScheduledScalings * numSteps < 0: self.w2._numScheduledScalings = numSteps anim = QtCore.QTimeLine(350, self.w2) anim.setUpdateInterval(20) anim.valueChanged.connect(self.w2.scalingTime) anim.finished.connect(self.w2.animFinished) anim.start() def scalingTime(self, x): factor = 1.0 + float(self.w2._numScheduledScalings) / 300.0 self.scale(factor, factor) def animFinished(self): if self.w2._numScheduledScalings > 0: self.w2._numScheduledScalings -= 1 else: self.w2._numScheduledScalings += 1 def mousePressEvent(self, event): p = self.w2.mapToScene(event.pos()) if event.button() == QtCore.Qt.MidButton: self.w2.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) event = QtGui.QMouseEvent( QtCore.QEvent.GraphicsSceneDragMove, event.pos(), QtCore.Qt.MouseButton.LeftButton, QtCore.Qt.MouseButton.LeftButton, QtCore.Qt.KeyboardModifier.NoModifier ) elif event.button() == QtCore.Qt.LeftButton: self.w2.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag) self.w2.coordinates = [p.x(), p.y()] QtWidgets.QGraphicsView.mousePressEvent(self.w2, event) def mouseReleaseEvent(self, event): QtWidgets.QGraphicsView.mouseReleaseEvent(self.w2, event) self.w2.setDragMode(QtWidgets.QGraphicsView.NoDrag) if event.button() == QtCore.Qt.LeftButton: p = self.w2.mapToScene(event.pos()) self.w2.coordinates.extend([p.x(), p.y()]) text = 'select area : ' + ','.join([ str(int(c)) for c in self.w2.coordinates]) self.w2.label.setText(text) def show(self): self.w2.exec_() class window(QWidget): def __init__(self): # super(window, self).__init__(parent) super().__init__() self.initUI() def initUI(self): global table_,titleEdit,authorEdit,table_1_Edit global z1_s,r1_s,table_s,g1 global num1,num2,data print(num1) self.centralwidget = QtWidgets.QWidget(self) self.view = QtWidgets.QTableView(self.centralwidget) self.table = TableView(data, num2, num1, self) self.button = QPushButton('削除', self) def main(): global app,ex,g1 g1=0 app = QtWidgets.QApplication(sys.argv) ex = window() ex.show() sys.exit(app.exec_()) if __name__ == '__main__': main()

何卒、宜しくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問