在选项卡上设置小部件的绝对位置

时间:2019-07-13 14:27:08

标签: python pyqt5

我想移动选项卡上的按钮并调整其大小。 我尝试移动并调整大小,但失败

import sys
import numpy as np
from PyQt5.QtWidgets import QMainWindow, QPushButton, QTabWidget, QVBoxLayout, QApplication, QWidget, QTableWidget, QTableWidgetItem
from PyQt5.QtCore import pyqtSlot
from PyQt5 import QtCore
from datetime import date
from PyQt5.QtGui import QFont
from sklearn.externals import joblib

class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.title = 'Price Prediction Tool'
        self.left = 0
        self.top = 0
        self.width = 620
        self.height = 520
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        self.table_widget = MyTableWidget(self)
        self.setCentralWidget(self.table_widget)

        self.show()

class MyTableWidget(QWidget):

    def __init__(self, parent):
        super(QWidget, self).__init__(parent)
        self.layout = QVBoxLayout(self)

        # Initialize tab screen
        self.tabs = QTabWidget()
        self.tab1 = QWidget()
        self.tab2 = QWidget()
        self.tabs.resize(600,500)

        # Add tabs
        self.tabs.addTab(self.tab1,"tab1")
        self.tabs.addTab(self.tab2,"tab2")

        # Create first tab
        self.tab1.layout = QVBoxLayout(self)
        self.tab2.layout = QVBoxLayout(self)

        self.button = QPushButton('Click', self)#'Predict', self
        self.button.clicked.connect(self.on_click)
        self.button.resize(10, 20)
        self.button.move(100, 200)
        self.tab1.layout.addWidget(self.button)

        self.tab1.setLayout(self.tab1.layout)


        # Add tabs to widget
        self.layout.addWidget(self.tabs)
        self.setLayout(self.layout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())```

0 个答案:

没有答案