PySide QlistWidget selected Item directory(path) - python

I have a problem; How can i get the path (directory) from "QListWidget" selected item.
When I 'am using os.path, this gives me Autodesk Maya Directory. But i need directory of my selected item from QListWidget item.
from PySide.QtGui import *
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
import os
import maya.cmds as cm
Import maya commands from maya as cm. This not include python source files.
class projectManagerMainWindow(MayaQWidgetDockableMixin, QWidget):
def __init__(self):
super(projectManagerMainWindow, self).__init__()
self.selectProject = QComboBox()
self.selectProject.setFixedHeight(30)
items = ["Main Projects","Assets"]
self.selectProject.addItems(items)
self.createNewProject = QPushButton()
self.createNewProject.setFixedSize(100,30)
icon = QPixmap('C:/Users/Faithcure/Documents/maya/2016/scripts/projectManager/new.png')
self.createNewProject.setText("New Project")
self.createNewProject.setIcon(icon)
self.dir_label = QLabel()
def select_driectory():
select_path = cm.fileDialog2(fileMode=3, okc = "Select")
self.sceneList.clear()
for path in select_path:
folders = os.listdir(path)
self.sceneList.addItems(folders)
self.dir_label.setText(path)
self.choose_directory = QPushButton()
self.choose_directory.setText("Directory")
self.choose_directory.setIcon(icon)
self.choose_directory.setFixedSize(100,30)
self.choose_directory.clicked.connect(select_driectory)
def new_project_window():
import newProject
reload(newProject)
ui = newProject.start()
ui.exec_()
def selected_item_path():
pass
self.createNewProject.clicked.connect(new_project_window)
This is Qlistwidget from selected directory items.
self.sceneLabel = QLabel()
self.sceneLabel.setText("Episodes: ")
self.sceneList = QListWidget()
self.sceneList.itemClicked.connect(selected_item_path)
And this is my second list widget (i want to list under the selected directories folder from scneneList Widget...
self.shotLabel = QLabel("Shots: ")
self.shotList = QListWidget()
self.topLayout = QHBoxLayout()
self.topLayout.addWidget(self.selectProject)
self.topLayout.addWidget(self.createNewProject)
self.topLayout.addWidget(self.choose_directory)
self.secondLayout = QVBoxLayout()
self.thirdLayout = QHBoxLayout()
self.thirdLayout.addWidget(self.sceneList)
self.thirdLayout.addWidget(self.shotList)
self.labels = QHBoxLayout()
self.labels.addWidget(self.sceneLabel)
self.labels.addWidget(self.shotLabel)
self.saveSceneVer = QPushButton()
self.saveSceneVer.setText("Save New Version")
self.saveSceneVer.setFixedHeight(30)
self.saveSceneVer.setStyleSheet("background-color:#00aff0")
self.openTrack = QPushButton()
self.openTrack.setText("Open Track")
self.openTrack.setFixedHeight(30)
self.openTrack.setStyleSheet("background-color:#ff5a80")
self.opButtons = QHBoxLayout()
self.opButtons.addWidget(self.saveSceneVer)
self.opButtons.addWidget(self.openTrack)
#Tab section for a lat of operations!
self.operation_tabs = QTabWidget()
tabWidget_Animation = QWidget()
optimize_for_animator_scene = QPushButton()
optimize_for_animator_scene.setText("I am an Animator")
create_render_camera = QPushButton()
create_render_camera.setText("Create Camera")
make_playblast = QPushButton()
make_playblast.setText("Playblast")
tabWidget_Animation_Layout = QGridLayout()
tabWidget_Animation.setLayout(tabWidget_Animation_Layout)
tabWidget_Animation_Layout.addWidget(optimize_for_animator_scene,0,0,0)
tabWidget_Animation_Layout.addWidget(create_render_camera, 0,1,0)
tabWidget_Animation_Layout.addWidget(make_playblast, 0,2,0)
tabWidget_render = QWidget()
tabWidget_td = QWidget()
self.operation_tabs.addTab(tabWidget_Animation,"Animation")
self.operation_tabs.addTab(tabWidget_render,"Render")
self.operation_tabs.addTab(tabWidget_td,"Compositing")
self.masterLayout = QVBoxLayout()
self.masterLayout.addLayout(self.topLayout)
self.masterLayout.addWidget(self.dir_label)
self.masterLayout.addLayout(self.secondLayout)
self.masterLayout.addLayout(self.labels)
self.masterLayout.addLayout(self.thirdLayout)
self.masterLayout.addLayout(self.opButtons)
self.masterLayout.addWidget(self.operation_tabs)
self.setLayout(self.masterLayout)
def start():
ui = projectManagerMainWindow()
ui.setWindowTitle("Project Manager")
ui.setFixedWidth(400)
ui.show(dockable=True, floating=False, area='right')
return ui
Here is script for Autodesk Maya.

Related

PySide6 Layout add space between items

I am using the QVBoxLayout from PySide6 to organize some items.
I now want to add some more space between the "Search" button and the "Modbus Data" group box.
They are all located inside the same QVBoxLaxout.
Here is the code which creates the displayed UI.
def setup_ui(self):
v_layout_base = QVBoxLayout(self)
h_layout_com_list = QHBoxLayout(self)
h_layout_com_list.addWidget(QLabel("Modbus COM"))
self.lw_com = QListWidget(self)
h_layout_com_list.addWidget(self.lw_com)
h_layout_search = QHBoxLayout(self)
self.button_search_com = QPushButton("Search")
h_layout_search.addWidget(self.button_search_com)
group_box = QGroupBox(QTranslator.tr("Modbus data"))
v_layout_modbus_data = QVBoxLayout(self)
h_layout_baudrate = QHBoxLayout(self)
h_layout_baudrate.addWidget(QLabel("Baudrate"))
self.cB_baudrate = QComboBox()
h_layout_baudrate.addWidget(self.cB_baudrate)
h_layout_bytesize = QHBoxLayout(self)
h_layout_bytesize.addWidget(QLabel("Bytesize"))
self.cB_bytesize = QComboBox()
h_layout_bytesize.addWidget(self.cB_bytesize)
h_layout_parity = QHBoxLayout(self)
h_layout_parity.addWidget(QLabel("Parity"))
self.cB_parity = QComboBox()
h_layout_parity.addWidget(self.cB_parity)
h_layout_stop_bit = QHBoxLayout(self)
h_layout_stop_bit.addWidget(QLabel("Stop bit"))
self.cB_stop_bit = QComboBox()
h_layout_stop_bit.addWidget(self.cB_stop_bit)
h_layout_connect = QHBoxLayout(self)
self.pb_connect = QPushButton("Connect")
self.pb_com_search = QPushButton("Disconnect")
h_layout_connect.addWidget(self.pb_connect)
h_layout_connect.addWidget(self.pb_com_search)
h_layout_com_label = QHBoxLayout(self)
h_layout_com_label.addWidget(QLabel("COM:"))
self.button_com_connect_label = QLabel("No COM selected")
h_layout_com_label.addWidget(self.button_com_connect_label)
h_layout_modbus_label = QHBoxLayout(self)
h_layout_modbus_label.addWidget(QLabel("Modbus:"))
self.button_modbus_connect_label = QLabel("Not connected to Modbus")
h_layout_modbus_label.addWidget(self.button_modbus_connect_label)
v_layout_base.addLayout(h_layout_com_list)
v_layout_base.addLayout(h_layout_search, 100)
v_layout_modbus_data.addLayout(h_layout_baudrate)
v_layout_modbus_data.addLayout(h_layout_bytesize)
v_layout_modbus_data.addLayout(h_layout_parity)
v_layout_modbus_data.addLayout(h_layout_stop_bit)
group_box.setLayout(v_layout_modbus_data)
v_layout_base.addWidget(group_box)
v_layout_base.addLayout(h_layout_connect)
v_layout_base.addLayout(h_layout_com_label)
v_layout_base.addLayout(h_layout_modbus_label)

Widgets cross over the tab on Pyqt5

I am trying to build a simple desktop application which can show and play all the movies in one place. This app includes several tabs, which contain different categories of movies.
The problem is the widgets i put inside the tab windows cross over the tab title. I don't know why.
This is my code:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class Filmler(QTabWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Filmler")
self.setWindowIcon(QIcon("film.jpg"))
self.setGeometry(200,100,1000,500)
self.tab1 = QWidget()
self.tab2 = QWidget()
self.tab3 = QWidget()
self.tab4 = QWidget()
self.tab1UI()
self.tab2UI()
self.tab3UI()
self.tab4UI()
self.addTab(self.tab1, "Hollywood")
self.addTab(self.tab2, "Bollywood")
self.addTab(self.tab3, "Uyghur")
self.addTab(self.tab4, "Zumra'nin Filmleri")
self.show()
def tab1UI(self):
# adding variables
# 1st movie
movie1_poster = QLabel()
movie1_poster.setPixmap(QPixmap("equalizer2.jpg"))
movie1_name = QLabel("Equalizer 2")
movie1_name.setAlignment(Qt.AlignCenter)
movie1_name.setFont(QFont("Times", 13))
movie1_link = QPushButton("izle")
vbox1 = QVBoxLayout()
vbox1.addWidget(movie1_name)
vbox1.addWidget(movie1_poster)
vbox1.addWidget(movie1_link)
vbox1.addStretch()
hbox = QHBoxLayout()
hbox.addLayout(vbox1)
hbox.addStretch()
self.setLayout(hbox)
def tab2UI(self):
pass
def tab3UI(self):
pass
def tab4UI(self):
pass
app = QApplication(sys.argv)
filmler = Filmler()
sys.exit(app.exec_())
This is the result.
Set parent self.tab1 to QHBoxLayout
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class Filmler(QTabWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Filmler")
self.setWindowIcon(QIcon("film.jpg"))
self.setGeometry(200,100,1000,500)
self.tab1 = QWidget()
self.tab2 = QWidget()
self.tab3 = QWidget()
self.tab4 = QWidget()
self.tab1UI()
self.tab2UI()
self.tab3UI()
self.tab4UI()
self.addTab(self.tab1, "Hollywood")
self.addTab(self.tab2, "Bollywood")
self.addTab(self.tab3, "Uyghur")
self.addTab(self.tab4, "Zumra'nin Filmleri")
self.show()
def tab1UI(self):
# adding variables
# 1st movie
movie1_poster = QLabel()
movie1_poster.setPixmap(QPixmap("lena.jpg"))
movie1_name = QLabel("Equalizer 2")
movie1_name.setAlignment(Qt.AlignCenter)
movie1_name.setFont(QFont("Times", 13))
movie1_link = QPushButton("izle")
vbox1 = QVBoxLayout()
vbox1.addWidget(movie1_name)
vbox1.addWidget(movie1_poster)
vbox1.addWidget(movie1_link)
vbox1.addStretch()
hbox = QHBoxLayout(self.tab1) # + self.tab1
hbox.addLayout(vbox1)
hbox.addStretch()
# self.setLayout(hbox) # ---
def tab2UI(self):
pass
def tab3UI(self):
pass
def tab4UI(self):
pass
app = QApplication(sys.argv)
filmler = Filmler()
sys.exit(app.exec_())

Unable to resize QTableWidget

I m trying to resize a table widget inside a QVBoxlayout which I further add as a row to a QFormlayout in pyqt
I m currently adding a QVboxlayout which contains a table widget inside it as a row in a Qformlayout.
And the main aim is to strecth the Table widget till the end of the application window that it acquires the left over space on the window
Using the below code -
class PGSearchDetails():
def __init__(self,parent=None):
self.widget_pgsd = QWidget()
self.layout_pgsd = QFormLayout()
self.layout_pgsd.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy(2|1))
self.PG_Id = QLineEdit()
#rx = QRegExp("^\\D+[!,#,#,$,%,\^,&,*,(,),:,\",{,},?,<,>,|,+,-,~,]")
#rx = QRegExp(" (?!(#,#,$|%|\^|&|*|(|)|:|\"|{|}|?|<|>|\||+|-|~|!))[\\w]+")
str_rx = QRegExp("^[A-Za-z*]{20}(?!##$%^&*():\"\{\}?<>\|+-~!_-)")
adhr_rx = QRegExp("[A-Z0-9]{12}(?!##$%^&*():\"\{\}?<>\|+-~!_)")
val = QRegExpValidator(str_rx)
val3 = QRegExpValidator(adhr_rx)
self.PG_Id.setValidator(val3)
self.LastName = QLineEdit()
self.LastName.setValidator(val)
self.MobNum = QLineEdit()
qint_val = QIntValidator()
qint_val.setTop(10)
self.MobNum.setValidator(qint_val)
self.layout_pgsd.addRow("First Name",self.PG_Id)
self.layout_pgsd.addRow("Last Name",self.LastName)
self.layout_pgsd.addRow("Mobile Number",self.MobNum)
update_layout_pgsd = QHBoxLayout()
layout_test,table = dbv.Search_View(self.getT)
#layout_test.setGeometry(QRect(200,200,50,50))
#table.setMaximumHeight(800)
#table.setGeometry(200,200,200,200)
#table.setGeometry(1,1,1000,600)
table.resize(1000,600)
update_btn_pgsd = QPushButton('Update')
reset_btn_pgsd = QPushButton('Reset')
update_layout_pgsd.addWidget(update_btn_pgsd)
update_layout_pgsd.addWidget(reset_btn_pgsd)
self.layout_pgsd.addRow(update_layout_pgsd)
##Adding the Table Widget to FormLayot
self.layout_pgsd.addRow(layout_test)
update_btn_pgsd.clicked.connect(partial(self.database,table,self.MobNum,
self.LastName))
#self.widget.setLayout(self.layout_pgsd)
def returnLayout(self):
return self.layout_pgsd
def returnWidget(self):
return self.widget_pgsd
def getT(self,linedit):
print("LE--->",linedit.text())
QtableWidget setup ---
def Search_View(self):
print("Inside Search_view")
central_widget = QWidget() # Create a central widget
db_layout = QVBoxLayout()
#col_count = len(self.pg_details.__dict__.keys())
col_count = 3
table = QTableWidget() # Create a table
#central_widget.setGeometry(200,200,150,150)
#table.maximumSize()
#db_layout.setMaximumSize(200)
db_layout.setGeometry(QRect(0,0,100,30))
db_layout.addWidget(table)
##Tried resizing the Table widget but nothing seems to works
table.resize(1000,600)
table.setGeometry(0,2,1000,600)
#central_widget.resize(central_widget.sizeHint())
#central_widget.setColumnWidth(1000,600)
#db_layout.addItem(update_layout)
central_widget.setLayout(db_layout)
print("Geometry H--->",table.geometry().height())
print("Geometry W--->",table.geometry().width())
print("Geometry X--->",table.geometry().x())
print("Geometry Y--->",table.geometry().y())
return central_widget,table
After the resize function, The table geometry changes to 1000,600 but on the screen it is not reflected. On the app screen it remains the same size everytime
Also find the entire code which contains the Tablayouts as well and Stacked widget for individual radio buttons
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.tab_widget = MainTabWindow()
self.setCentralWidget(self.tab_widget)
self.show()
class MainTabWindow(QTabWidget):
def __init__(self,parent=None):
super(MainTabWindow, self).__init__(parent)
self.init_ui()
def init_ui(self):
self.setWindowTitle('PyQt5 Tab Example')
self.tab1 = QWidget()
self.addTab(self.tab1,"Search")
self.PGSearchTab()
def PGSearchTab(self):
print("Search Tab First Tab")
self.central_layout = QVBoxLayout()
self.stack1 = QWidget()
self.stack2 = QWidget()
self.stack3 = QWidget()
self.stack_widget = QStackedWidget()
button_layout = QHBoxLayout()
radio_button_1 = QRadioButton("Search")
radio_button_2 = QRadioButton("Add")
radio_button_3 = QRadioButton("Update")
button_layout.addWidget(radio_button_1)
button_layout.addWidget(radio_button_2)
button_layout.addWidget(radio_button_3)
self.central_layout.addItem(button_layout)
self.stack_widget.addWidget(self.stack1)
self.stack_widget.addWidget(self.stack2)
self.stack_widget.addWidget(self.stack3)
self.central_layout.addWidget(self.stack_widget)
radio_button_1.toggled.connect(lambda :self.SelectButtonCheck(radio_button_1))
self.setTabText(0,"Search")
update_layout = QHBoxLayout()
update_layout.setAlignment(QtCore.Qt.AlignBottom)
update_btn = QPushButton('Update')
reset_btn = QPushButton('Reset')
update_layout.addWidget(update_btn)
update_layout.addWidget(reset_btn)
self.tab1.setLayout(self.central_layout)
def SelectButtonCheck(self,b):
if b.text() == "Search":
if b.isChecked():
print(b.text()+ "is selected")
self.obj_pgsd = pgsd.PGSearchDetails()
layout = self.obj_pgsd.returnLayout()
if self.stack1.layout() is None:
self.stack1.setLayout(layout)
self.stack_widget.setCurrentIndex(0)
def main():
application = QApplication(sys.argv)
main_window = MainTabWindow()
main_window.show()
sys.exit(application.exec_())
if __name__ == '__main__':
main()
I do not seem to understand what is I m missing here
Any pointers would be appreciated.
Also find the working code to execute the above layout setup.
#!/usr/local/bin/python3
import sys
from PyQt5.QtWidgets import (QApplication, QWidget,QMainWindow,QLineEdit,QAction,
QLabel,QPushButton,QVBoxLayout,
QTabWidget,QFormLayout,QHBoxLayout,
QRadioButton,QCheckBox,QTextEdit,
QListView,QDialogButtonBox,QSizePolicy,QCalendarWidget)
from PyQt5 import QtCore
import PyQt5.Qt
from PyQt5.Qt import *
from PyQt5.QtCore import pyqtSlot
from PyQt5 import QtSql
from functools import partial
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.tab_widget = MainTabWindow()
self.setCentralWidget(self.tab_widget)
self.show()
class MainTabWindow(QTabWidget):
def __init__(self,parent=None):
super(MainTabWindow, self).__init__(parent)
self.init_ui()
def init_ui(self):
self.setWindowTitle('PyQt5 Tab Example')
self.tab1 = QWidget()
self.addTab(self.tab1,"Search")
self.PGSearchTab()
def PGSearchTab(self):
print("Search Tab First Tab")
self.central_layout = QVBoxLayout()
self.stack1 = QWidget()
self.stack2 = QWidget()
self.stack3 = QWidget()
self.stack_widget = QStackedWidget()
button_layout = QHBoxLayout()
radio_button_1 = QRadioButton("Search")
radio_button_2 = QRadioButton("Add")
radio_button_3 = QRadioButton("Update")
button_layout.addWidget(radio_button_1)
button_layout.addWidget(radio_button_2)
button_layout.addWidget(radio_button_3)
self.central_layout.addItem(button_layout)
self.stack_widget.addWidget(self.stack1)
self.stack_widget.addWidget(self.stack2)
self.stack_widget.addWidget(self.stack3)
self.central_layout.addWidget(self.stack_widget)
radio_button_1.toggled.connect(lambda :self.SelectButtonCheck(radio_button_1))
self.setTabText(0,"Search")
update_layout = QHBoxLayout()
update_layout.setAlignment(QtCore.Qt.AlignBottom)
update_btn = QPushButton('Update')
reset_btn = QPushButton('Reset')
update_layout.addWidget(update_btn)
update_layout.addWidget(reset_btn)
self.tab1.setLayout(self.central_layout)
def SelectButtonCheck(self,b):
if b.text() == "Search":
if b.isChecked():
print(b.text()+ "is selected")
self.obj_pgsd = PGSearchDetails()
layout = self.obj_pgsd.returnLayout()
if self.stack1.layout() is None:
self.stack1.setLayout(layout)
self.stack_widget.setCurrentIndex(0)
class PGSearchDetails():
def __init__(self,parent=None):
self.widget_pgsd = QWidget()
self.layout_pgsd = QFormLayout()
self.layout_pgsd.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy(2|1))
self.PG_Id = QLineEdit()
#rx = QRegExp("^\\D+[!,#,#,$,%,\^,&,*,(,),:,\",{,},?,<,>,|,+,-,~,]")
#rx = QRegExp(" (?!(#,#,$|%|\^|&|*|(|)|:|\"|{|}|?|<|>|\||+|-|~|!))[\\w]+")
str_rx = QRegExp("^[A-Za-z*]{20}(?!##$%^&*():\"\{\}?<>\|+-~!_-)")
adhr_rx = QRegExp("[A-Z0-9]{12}(?!##$%^&*():\"\{\}?<>\|+-~!_)")
val = QRegExpValidator(str_rx)
val3 = QRegExpValidator(adhr_rx)
self.PG_Id.setValidator(val3)
self.LastName = QLineEdit()
self.LastName.setValidator(val)
self.MobNum = QLineEdit()
qint_val = QIntValidator()
qint_val.setTop(10)
self.MobNum.setValidator(qint_val)
self.layout_pgsd.addRow("First Name",self.PG_Id)
self.layout_pgsd.addRow("Last Name",self.LastName)
self.layout_pgsd.addRow("Mobile Number",self.MobNum)
update_layout_pgsd = QHBoxLayout()
layout_test,table = self.Search_View(self.getT)
#layout_test.setGeometry(QRect(200,200,50,50))
#table.setMaximumHeight(800)
#table.setGeometry(200,200,200,200)
#table.setGeometry(1,1,1000,600)
table.resize(1000,600)
update_btn_pgsd = QPushButton('Update')
reset_btn_pgsd = QPushButton('Reset')
update_layout_pgsd.addWidget(update_btn_pgsd)
update_layout_pgsd.addWidget(reset_btn_pgsd)
self.layout_pgsd.addRow(update_layout_pgsd)
##Adding the Table Widget to FormLayot
self.layout_pgsd.addRow(layout_test)
update_btn_pgsd.clicked.connect(partial(self.database,table,self.MobNum,
self.LastName))
#self.widget.setLayout(self.layout_pgsd)
def returnLayout(self):
return self.layout_pgsd
def returnWidget(self):
return self.widget_pgsd
def getT(self,linedit):
print("LE--->",linedit.text())
def Search_View(self,text):
print("Inside Search_view")
central_widget = QWidget() # Create a central widget
db_layout = QVBoxLayout()
#col_count = len(self.pg_details.__dict__.keys())
col_count = 3
table = QTableWidget() # Create a table
#central_widget.setGeometry(200,200,150,150)
#table.maximumSize()
#db_layout.setMaximumSize(200)
db_layout.setGeometry(QRect(0,0,100,30))
db_layout.addWidget(table)
##Tried resizing the Table widget but nothing seems to works
table.resize(1000,600)
table.setGeometry(0,2,1000,600)
#central_widget.resize(central_widget.sizeHint())
#central_widget.setColumnWidth(1000,600)
#db_layout.addItem(update_layout)
central_widget.setLayout(db_layout)
print("Geometry H--->",table.geometry().height())
print("Geometry W--->",table.geometry().width())
print("Geometry X--->",table.geometry().x())
print("Geometry Y--->",table.geometry().y())
return central_widget,table
def SqlExec(self,text):
db = QtSql.QSqlDatabase.addDatabase('QMYSQL')
db.setHostName('localhost')
db.setDatabaseName('Test')
db.setUserName('root')
db.open()
query = QtSql.QSqlQuery()
select = "select * from Test.PG_Details where PG_Id=?"# where PG_Id = 1"
query.prepare(select)
indexes = range(3)
print("TEXT----->",text)
query.addBindValue(text)
#query.exec_(select)
query.exec_()
print("Sizze----",query.size())
row_count = query.size()
db.record('PG_Details')
col_list = []
for i in range(db.record('PG_Details').count()):
print("FIELD----->",db.record('PG_Details').field(i).name())
col_list.append(db.record('PG_Details').field(i).name())
db.close()
return query,row_count,col_list
def database(self,table,text,text2):
text = text.text()
query_result,row_count,col_list = self.SqlExec(text)
i = 0
table.setColumnCount(3) #Set three columns
table.setRowCount(row_count)
table.setHorizontalHeaderLabels(col_list)
while query_result.next():
#print(query_result.value(i))
result_row = [query_result.value(index) for index in range(query_result.record().count())]
#print("RR--->",result_row)
for idx,val in enumerate(result_row):
#print("IDX----->",idx)
table.setItem(i, idx, QTableWidgetItem(val))
i = i + 1
def main():
application = QApplication(sys.argv)
main_window = MainTabWindow()
main_window.show()
sys.exit(application.exec_())
if __name__ == '__main__':
main()
The problem is that QFormLayout makes every time you add a widget using addRow () uses strech, the solution is to use a QVBoxLayout, and in that QVBoxLayout is to pass the QFormLayout and the layout_test.
class PGSearchDetails():
def __init__(self,parent=None):
self.widget_pgsd = QWidget()
self.layout = QVBoxLayout() # <---
self.layout_pgsd = QFormLayout()
self.layout.addLayout(self.layout_pgsd) # <---
self.layout_pgsd.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy(2|1))
...
self.layout_pgsd.addRow(update_layout_pgsd)
##Adding the Table Widget to FormLayot
# self.layout_pgsd.addRow(layout_test)
self.layout.addWidget(layout_test) # <---
update_btn_pgsd.clicked.connect(partial(self.database,table,self.MobNum,
self.LastName))
def returnLayout(self):
return self.layout # <---

PyQt - Tabbed dialog not displaying embedded widgets

I am trying to create a dialog with three tabs using PyQt. However, I am annoyed because although the dialog is displayed, the embedded widgets are not displayed!. I suppose this is a very simple problem with a correspondingly very simple solution, but I am struck! Can anyone give a hint? Thanks in advance!
Here is my code so far:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class TabbedDialog(QDialog):
def __init__(self, parent = None):
super(TabbedDialog, self).__init__(parent)
self.tabWidget = QTabWidget()
self.tabWidget.tab1 = QWidget()
self.tabWidget.tab2 = QWidget()
self.tabWidget.tab3 = QWidget()
self.tabWidget.addTab(self.tabWidget.tab1,"Tab 1")
self.tabWidget.addTab(self.tabWidget.tab2,"Tab 2")
self.tabWidget.addTab(self.tabWidget.tab3,"Tab 3")
self.tab1UI()
self.tab2UI()
self.tab3UI()
self.setWindowTitle("tab demo")
def tab1UI(self):
layout = QFormLayout()
layout.addRow("Name",QLineEdit())
layout.addRow("Address",QLineEdit())
self.tabWidget.setTabText(0,"Contact Details")
self.tabWidget.tab1.setLayout(layout)
def tab2UI(self):
layout = QFormLayout()
sex = QHBoxLayout()
sex.addWidget(QRadioButton("Male"))
sex.addWidget(QRadioButton("Female"))
layout.addRow(QLabel("Sex"),sex)
layout.addRow("Date of Birth",QLineEdit())
self.tabWidget.setTabText(1,"Personal Details")
self.tabWidget.tab2.setLayout(layout)
def tab3UI(self):
layout = QHBoxLayout()
layout.addWidget(QLabel("subjects"))
layout.addWidget(QCheckBox("Physics"))
layout.addWidget(QCheckBox("Maths"))
self.tabWidget.setTabText(2,"Education Details")
self.tabWidget.tab3.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
form = TabbedDialog()
retval = form.exec_()
here is my solution to the problem
On the init method, I declared a layout, then added the 'tabWidget' widget to that layout and set that layout as the layout of your QDialog.
def __init__(self, parent = None):
super(TabbedDialog, self).__init__(parent)
self.tabWidget = QTabWidget()
self.tabWidget.tab1 = QWidget()
self.tabWidget.tab2 = QWidget()
self.tabWidget.tab3 = QWidget()
self.tabWidget.addTab(self.tabWidget.tab1,"Tab 1")
self.tabWidget.addTab(self.tabWidget.tab2,"Tab 2")
self.tabWidget.addTab(self.tabWidget.tab3,"Tab 3")
self.tab1UI()
self.tab2UI()
self.tab3UI()
self.setWindowTitle("tab demo")
# Here is the addition to the code.
mainLayout = QVBoxLayout()
mainLayout.addWidget(self.tabWidget)
self.setLayout(mainLayout)

load image from the Top in TabWidget from PyQt

Below code, image loading from the specific Path and placing on the bottom of the Window.Here i need to load image from the top.So for that i need to change the placement of the Tab Widget(Tab01,Tab02,Tab03).
I am unable to load the image from the top and unable to change the position of the Tab Widget.How to do this and how to load the Image from the top.
import re,sys,os
from PyQt4 import QtGui,QtCore
class projs(QtGui.QWidget):
def __init__(self, parent=None):
super(projs,self).__init__(parent)
self.setWindowTitle(" V1.0 ")
tab_widget = QtGui.QTabWidget()
proj = QtGui.QWidget()
asset = QtGui.QWidget()
shots = QtGui.QWidget()
tab_widget.addTab(proj, "Tab01")
tab_widget.addTab(asset, "Tab02")
tab_widget.addTab(shots, "Tab03")
self.projPathLabel = QtGui.QLabel("Project Path ",proj)
self.projPathLabel.setGeometry(10,20,100,25)
self.assetPathLabel = QtGui.QLabel("Project ",asset)
self.assetPathLabel.setGeometry(20,20,100,25)
self.shotPathLabel = QtGui.QLabel("Project ",shots)
self.shotPathLabel.setGeometry(20,20,100,25)
vbox = QtGui.QVBoxLayout()
vbox.addWidget(tab_widget)
self.setLayout(vbox)
p1_vbox = QtGui.QVBoxLayout(proj)
proj.setLayout(p1_vbox)
p2_vbox = QtGui.QVBoxLayout(asset)
asset.setLayout(p2_vbox)
p3_vbox = QtGui.QVBoxLayout(shots)
shots.setLayout(p3_vbox)
vuvupic = QtGui.QPixmap("C:\Users\name\Documents\config\Logo2.jpg")
label = QtGui.QLabel(self)
label.setPixmap(vuvupic)
vbox.addWidget(label)
app = QtGui.QApplication([])
win = projs()
win.resize(410,390)
win.show()
sys.exit(app.exec_())
By "from the top," do you mean that you want to have the image placed above the the TabWidget? QLayouts are ordered in the same order of vbox.addWidget() calls, which means you could just reorder the function calls to put the picture on top.
import re,sys,os
from PyQt4 import QtGui,QtCore
class projs(QtGui.QWidget):
def __init__(self, parent=None):
super(projs,self).__init__(parent)
self.setWindowTitle(" V1.0 ")
tab_widget = QtGui.QTabWidget()
proj = QtGui.QWidget()
asset = QtGui.QWidget()
shots = QtGui.QWidget()
tab_widget.addTab(proj, "Tab01")
tab_widget.addTab(asset, "Tab02")
tab_widget.addTab(shots, "Tab03")
self.projPathLabel = QtGui.QLabel("Project Path ",proj)
self.projPathLabel.setGeometry(10,20,100,25)
self.assetPathLabel = QtGui.QLabel("Project ",asset)
self.assetPathLabel.setGeometry(20,20,100,25)
self.shotPathLabel = QtGui.QLabel("Project ",shots)
self.shotPathLabel.setGeometry(20,20,100,25)
vbox = QtGui.QVBoxLayout()
vuvupic = QtGui.QPixmap("C:\Users\name\Documents\config\Logo2.jpg")
label = QtGui.QLabel(self)
label.setPixmap(vuvupic)
vbox.addWidget(label)
vbox.addWidget(tab_widget)
self.setLayout(vbox)
p1_vbox = QtGui.QVBoxLayout(proj)
proj.setLayout(p1_vbox)
p2_vbox = QtGui.QVBoxLayout(asset)
asset.setLayout(p2_vbox)
p3_vbox = QtGui.QVBoxLayout(shots)
shots.setLayout(p3_vbox)
app = QtGui.QApplication([])
win = projs()
win.resize(410,390)
win.show()
sys.exit(app.exec_())
Also, for moderately sized project, you may want to look into using QtDesigner to build layouts. Googling "pyqt designer" will give you plenty of blogs and tutorials for getting started.

Categories

Resources