показать содержимое таба
В первом окне есть несколько табов, кнопка, чтобы открыть окно, где можно просмотреть их содержимое(слайд-шоу), в этом окне есть две кнопки: назад и вперед, чтобы листать табы. Как это реализовать? В моем коде уже можно добавлять текст и картинки к табам?
from PyQt5.QtWidgets import QWidget, QMainWindow, QFileDialog, QInputDialog, QLabel, QApplication
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtCore import QRect
from PyQt5 import uic
import sys
class FirstForm(QMainWindow):
def __init__(self):
super().__init__()
uic.loadUi('form1.ui', self)
self.secondForm = SecondForm()
self.slideshow = SlideShow()
self.pushButton.clicked.connect(self.secondForm.show)
self.secondForm.btn2_2.clicked.connect(self.addImage)
self.secondForm.btn2.clicked.connect(self.addText)
self.pushButton_2.clicked.connect(self.openshow)
def getWidgetGeometry(self):
try:
x = int(self.secondForm.height_2.text())
y = int(self.secondForm.lineEdit_2.text())
w = int(self.secondForm.lineEdit_3.text())
h = int(self.secondForm.lineEdit_4.text())
except:
x = 0
y = 0
w = 100
h = 100
return QRect(x, y, w, h)
def openshow(self):
self.slideshow.show()
def addImage(self):
result = QFileDialog.getOpenFileName(self.secondForm, 'Выбрать картинку', '')
if result[1]:
image = QImage(result[0])
label = QLabel('', self.tabWidget.currentWidget())
label.setPixmap(QPixmap.fromImage(image))
label.setGeometry(self.getWidgetGeometry())
label.show()
def addText(self):
result = QInputDialog.getText(self.secondForm, '', 'введите текст')
if result[1]:
label = QLabel(result[0], self.tabWidget.currentWidget())
label.setGeometry(self.getWidgetGeometry())
label.show()
class SecondForm(QWidget):
def __init__(self):
super().__init__()
uic.loadUi('form2.ui', self)
class SlideShow(QWidget):
def __init__(self):
super().__init__()
uic.loadUi('form3.ui', self)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = FirstForm()
ex.show()
sys.exit(app.exec_())
uic главного окна с табами:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>541</width>
<height>471</height>
</rect>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
</widget>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>60</x>
<y>480</y>
<width>181</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>Открыть второе окно</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>270</x>
<y>480</y>
<width>211</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>содержимое табов(слайд-шоу)</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
uic редактора( здесь можно вставлять картинки и тексты в табы первого окна):
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="btn2">
<property name="geometry">
<rect>
<x>50</x>
<y>40</y>
<width>101</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>текст</string>
</property>
</widget>
<widget class="QPushButton" name="btn2_2">
<property name="geometry">
<rect>
<x>50</x>
<y>130</y>
<width>101</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>картинка</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>190</x>
<y>40</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Положение</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>290</x>
<y>40</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Размеры</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>200</x>
<y>70</y>
<width>31</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>200</x>
<y>130</y>
<width>31</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_3">
<property name="geometry">
<rect>
<x>290</x>
<y>70</y>
<width>31</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_4">
<property name="geometry">
<rect>
<x>290</x>
<y>130</y>
<width>31</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
uic третьего окна( здесь нужно реализовать показ содержимого табов первого окна):
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>622</width>
<height>475</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>430</y>
<width>91</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Назад</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>110</x>
<y>430</y>
<width>91</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Вперед</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>