Issue
first off all; thanks for answers!
I created two different windows and two different Python file. i could connect them like this:
When I click to "New Project" button under the QlistWidget item then it opens.This is good but i have a problem. I want to connect QlineEdit (in QDialogWindow) to QlistWidget (in QMainWindow).
This is my MainWindow Codes:
from PySide.QtCore import *
from PySide.QtGui import *
import os, sys
import neworkdialog
class projectManager(QMainWindow, QObject):
def __init__(self):
super(projectManager, self).__init__()
self.managerUI()
def managerUI(self):
def generalClose():
sys.exit()
def itemListLabel():
itemChanged = self.workList.currentItem().text()
self.projectDescription.setText(itemChanged)
def newProject():
neworkdialog.start_nework()
self.menubar = QMenuBar()
self.fileMenu = self.menubar.addMenu("&File")
nw = self.fileMenu.addAction("New Work")
nw.setShortcut("ctrl+n")
nw.triggered.connect(newProject)
self.fileMenu.addAction("Delete Work")
self.fileMenu.addSeparator()
op = self.fileMenu.addAction("Open")
op.setShortcut("ctrl+o")
sv = self.fileMenu.addAction("Save")
sv.setShortcut("ctrl+s")
cs = self.fileMenu.addAction("Close")
cs.setShortcut("ctrl+q")
cs.triggered.connect(generalClose)
self.toolMenu = self.menubar.addMenu("&Tools")
self.toolMenu.addAction("Calculator")
self.toolMenu.addAction("Deadline(s)")
self.aboutMenu = self.menubar.addMenu("&Help")
self.aboutMenu.addAction("About")
self.aboutMenu.addAction("GameTime")
self.aboutMenu.addAction("Help")
self.setMenuBar(self.menubar)
self.workList = QListWidget()
# i = ["deneme1","bdeneme2","adeneme3"]
# self.workList.addItems(i)
self.workList.setMaximumWidth(275)
self.newProjectButton = QPushButton()
self.newProjectButton.setText("New Project")
self.newProjectButton.clicked.connect(newProject)
self.delProjectButton = QPushButton()
self.delProjectButton.setText("Delete Project")
self.projectDescription = QLabel()
self.projectDescription.setText("Project Title")
self.workList.itemClicked.connect(itemListLabel)
self.projectDescription.setStyleSheet("font: 22pt")
self.widgets = QWidget()
self.mainLayout = QHBoxLayout()
self.workListLayout = QVBoxLayout()
self.workListLayout.addWidget(self.workList)
self.projectDescriptionLayout = QHBoxLayout()
self.projectDescriptionLayout.addWidget(self.projectDescription)
self.workButtonLayout = QHBoxLayout()
self.workButtonLayout.addWidget(self.newProjectButton)
self.workButtonLayout.addWidget(self.delProjectButton)
self.workListLayout.addLayout(self.workButtonLayout)
self.mainLayout.addLayout(self.workListLayout)
self.mainLayout.addLayout(self.projectDescriptionLayout)
self.widgets.setLayout(self.mainLayout)
self.setCentralWidget(self.widgets)
def start():
app = QApplication(sys.argv)
ui = projectManager()
ui.setWindowTitle("Projects Manager v.01")
ui.setFixedSize(1280, 920)
ui.show()
sys.exit(app.exec_())
if __name__ == '__main__':
start()
And this is my Qdialog codes:
from PySide.QtCore import *
from PySide.QtGui import *
import os, sys
import _projectMainWindow
class neworkdialogs (QDialog, QObject):
def __init__(self):
super(neworkdialogs, self).__init__()
self.dialogBuildUI()
def dialogBuildUI(self):
print _projectMainWindow
def setProjectTitle():
setWindowText = self.projectName.text()
self.setWindowTitle(setWindowText)
def generalExit():
sys.exit()
self.projectName = QLineEdit()
self.projectName.setPlaceholderText("Set Project Name")
self.projectName.textChanged.connect(setProjectTitle)
self.projectPrice = QLineEdit()
self.projectPrice.setPlaceholderText("Set Money Count")
def addNewWrokToList():
ProjectNameOfText = self.projectName.text()
self.worklist.addItem(ProjectNameOfText)
priceItems = ["TL", "USD", "EUR"]
self.priceDoviz = QComboBox()
self.priceDoviz.addItems(priceItems)
self.AcceptButton = QPushButton("Create Work")
self.AcceptButton.clicked.connect(addNewWrokToList)
self.abondon = QPushButton("Abondon")
self.abondon.clicked.connect(generalExit)
self.dialogLayout = QVBoxLayout()
self.inputLayout = QHBoxLayout()
self.buttonLayout = QHBoxLayout()
self.inputLayout.addWidget(self.projectName)
self.inputLayout.addWidget(self.projectPrice)
self.inputLayout.addWidget(self.priceDoviz)
self.dialogLayout.addLayout(self.inputLayout)
self.dialogLayout.addLayout(self.buttonLayout)
self.buttonLayout.addWidget(self.AcceptButton)
self.buttonLayout.addWidget(self.abondon)
self.setLayout(self.dialogLayout)
def start_nework():
ui = neworkdialogs()
ui.setWindowTitle("Your job properties")
ui.show()
ui.exec_()
So, how can I connect different window and widgets? Thank you again :)
Solution
The function start_nework is inadequate for this case since access to the dialog is lost, the correct thing is to create an instance of neworkdialogs when the button is pressed. QDialog is oriented to handle the accept and reject functions so that afterwards the state returns, that is to say if the request is accepted or not, for this I have modified your class:
neworkdialog.py
from PySide.QtGui import *
class neworkdialogs(QDialog):
def __init__(self, *args, **kwargs):
super(neworkdialogs, self).__init__(*args, **kwargs)
self.dialogBuildUI()
def dialogBuildUI(self):
self.projectName = QLineEdit(self)
self.projectName.setPlaceholderText("Set Project Name")
self.projectName.textChanged.connect(self.setWindowTitle)
self.projectPrice = QLineEdit(self)
self.projectPrice.setPlaceholderText("Set Money Count")
priceItems = ["TL", "USD", "EUR"]
self.priceDoviz = QComboBox(self)
self.priceDoviz.addItems(priceItems)
self.AcceptButton = QPushButton("Create Work")
self.abondon = QPushButton("Abondon")
self.AcceptButton.clicked.connect(self.accept)
self.abondon.clicked.connect(self.reject)
self.dialogLayout = QVBoxLayout(self)
self.inputLayout = QHBoxLayout()
self.buttonLayout = QHBoxLayout()
self.inputLayout.addWidget(self.projectName)
self.inputLayout.addWidget(self.projectPrice)
self.inputLayout.addWidget(self.priceDoviz)
self.dialogLayout.addLayout(self.inputLayout)
self.dialogLayout.addLayout(self.buttonLayout)
self.buttonLayout.addWidget(self.AcceptButton)
self.buttonLayout.addWidget(self.abondon)
It is not appropriate to call sys.exit()
to exit a window, the correct thing to do is to use the close()
method. I have also implemented the logic to add the text to the QListWidget
.
main.py
from PySide.QtGui import *
import neworkdialog
class projectManager(QMainWindow):
def __init__(self, *args, **kwargs):
super(projectManager, self).__init__(*args, **kwargs)
self.managerUI()
def managerUI(self):
self.menubar = QMenuBar(self)
self.fileMenu = self.menubar.addMenu("&File")
nw = self.fileMenu.addAction("New Work")
nw.setShortcut("ctrl+n")
nw.triggered.connect(self.start_nework)
self.fileMenu.addAction("Delete Work")
self.fileMenu.addSeparator()
op = self.fileMenu.addAction("Open")
op.setShortcut("ctrl+o")
sv = self.fileMenu.addAction("Save")
sv.setShortcut("ctrl+s")
cs = self.fileMenu.addAction("Close")
cs.setShortcut("ctrl+q")
cs.triggered.connect(self.close)
self.toolMenu = self.menubar.addMenu("&Tools")
self.toolMenu.addAction("Calculator")
self.toolMenu.addAction("Deadline(s)")
self.aboutMenu = self.menubar.addMenu("&Help")
self.aboutMenu.addAction("About")
self.aboutMenu.addAction("GameTime")
self.aboutMenu.addAction("Help")
self.setMenuBar(self.menubar)
self.workList = QListWidget(self)
# i = ["deneme1","bdeneme2","adeneme3"]
# self.workList.addItems(i)
self.workList.setMaximumWidth(275)
self.newProjectButton = QPushButton(self)
self.newProjectButton.setText("New Project")
self.newProjectButton.clicked.connect(self.start_nework)
self.delProjectButton = QPushButton(self)
self.delProjectButton.setText("Delete Project")
self.projectDescription = QLabel("Project Title", self)
self.workList.itemClicked.connect(lambda item: self.projectDescription.setText(item.text()))
self.projectDescription.setStyleSheet("font: 22pt")
self.widgets = QWidget()
self.mainLayout = QHBoxLayout(self.widgets)
self.workListLayout = QVBoxLayout()
self.workListLayout.addWidget(self.workList)
self.workButtonLayout = QHBoxLayout()
self.workButtonLayout.addWidget(self.newProjectButton)
self.workButtonLayout.addWidget(self.delProjectButton)
self.workListLayout.addLayout(self.workButtonLayout)
self.mainLayout.addLayout(self.workListLayout)
self.mainLayout.addWidget(self.projectDescription)
self.setCentralWidget(self.widgets)
def start_nework(self):
w = neworkdialog.neworkdialogs(self)
if w.exec_() == QDialog.Accepted:
name = w.projectName.text()
self.workList.addItem(name)
def start():
import sys
app = QApplication(sys.argv)
ui = projectManager()
ui.setWindowTitle("Projects Manager v.01")
ui.setFixedSize(1280, 920)
ui.show()
sys.exit(app.exec_())
if __name__ == '__main__':
start()
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.