[PyQt] Question about laying out widgets.
Gabriele Visconti
gabriele.visconti at gmail.com
Thu Mar 26 14:20:39 GMT 2009
Hi I’m trying to build up something that for every push of a button, a row
of widgets is inserted within a layout. So if I press one time I have a row,
two times and the next row comes up, and so on…
If you try running the code below you will see that if you press the button
one time all goes well, but on the second time the new row is pasted upon
the first one and not next to it.
I’m quite a basic programmer in bot python and PyQt so I’m sure I’m missing
something basic. I tried using QformLayout insertRow method but I must
specify the row int and this I can’t do.
Again, in case I have several rows how to delete the specific one which has
the focus in the moment I press a “remove row” button?
Thank you very much for your help.
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class WizAndChipsCal(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self)
self.setWindowTitle("Wiz and Chips Calendar")
self.setWindowIcon(QIcon("C:/Python26/PyQt/Icon/date.png"))
self.setToolTip("Hello to this Wiz and Chips fancy
calendar!")
self.title = ("<font color=red size=3><b>"\
+ "Wiz and Chips Pushable Calendar!"\
+ "</font></b>")
self.Label = QLabel(self.title)
self.Label.setAlignment(Qt.AlignCenter | Qt.AlignJustify)
self.calendar = QCalendarWidget()
self.calendar.setGridVisible(1)
self.calendar.setMinimumHeight(180)
self.calendar.setMaximumHeight(180)
self.calendar.setMaximumWidth(250)
self.connect(self.calendar,
SIGNAL('selectionChanged()'),
self.SelDate)
self.AddButton = QPushButton("&AddProject")
self.connect(self.AddButton,
SIGNAL('pressed()'),
self.AddProj)
self.dateLabel = QLabel("Date:")
self.dateLabel.setMaximumWidth(80)
CurrDate = QDate.currentDate()
self.date = QDateEdit(CurrDate)
self.date.setCalendarPopup(1)
self.date.setMaximumWidth(80)
self.JobLabel = QLabel("Job No.")
self.JobLabel.setMaximumWidth(60)
self.JobNo = QTextEdit()
self.JobNo.setMaximumHeight(20)
self.JobNo.setMaximumWidth(60)
self.JobNo.setTabChangesFocus(1)
self.CustJobLabel = QLabel("Cust.Job")
self.CustJobLabel.setMaximumWidth(60)
self.CustJob = QTextEdit()
self.CustJob.setMaximumHeight(20)
self.CustJob.setMaximumWidth(60)
self.CustJob.setTabChangesFocus(1)
self.CustOrdLabel = QLabel("Cust.Ord.")
self.CustOrdLabel.setMaximumWidth(60)
self.CustOrd = QTextEdit()
self.CustOrd.setMaximumHeight(20)
self.CustOrd.setMaximumWidth(60)
self.CustOrd.setTabChangesFocus(1)
self.ProductLabel = QLabel("Product")
self.ProductLabel.setMaximumWidth(100)
self.Product = QTextEdit()
self.Product.setMaximumHeight(20)
self.Product.setMaximumWidth(150)
self.Product.setTabChangesFocus(1)
self.summaryBox = QGroupBox("Project Management Layout")
self.CloseButton = QPushButton("&Quit")
self.CloseButton.setToolTip("<font color=red size=2><b>"\
+ "Press here to Quit"\
+ "</font></b>")
self.CloseButton.setMaximumSize(50, 25)
GeneralLayout = QGridLayout()
GeneralLayout.addWidget(self.Label, 0, 0)
GeneralLayout.addWidget(self.AddButton, 1,0)
GeneralLayout.addWidget(self.calendar, 1, 1)
GeneralLayout.addWidget(self.CloseButton, 4, 0)
GeneralLayout.addWidget(self.summaryBox, 3, 0)
self.setLayout(GeneralLayout)
self.connect(self.CloseButton,
SIGNAL("pressed()"),
self.close)
def moveEvent(self, event):
self.setWindowOpacity(0.7)
QTimer.singleShot(50, self.opac)
def opac(self):
self.setWindowOpacity(1)
def closeEvent(self, event):
self.CloseDialog = QMessageBox.question(self, "The
application is being closed",
"Do you really want
to exit?",
QMessageBox.Save|QMessageBox.Yes|QMessageBox.Discard,
QMessageBox.Discard)
if self.CloseDialog == QMessageBox.Yes:
event.accept()
elif self.CloseDialog == QMessageBox.Save or
QMessageBox.Discard:
event.ignore()
def SelDate(self):
self.SelectedDate = self.calendar.selectedDate()
print(self.SelectedDate)
def AddProj(self):
projTextBoxesLayout = QHBoxLayout()
projTextBoxesLayout.addWidget(self.JobNo)
projTextBoxesLayout.addWidget(self.CustJob)
projTextBoxesLayout.addWidget(self.CustOrd)
projTextBoxesLayout.addWidget(self.Product)
projLabelLayout = QHBoxLayout()
projLabelLayout.addWidget(self.JobLabel)
projLabelLayout.addWidget(self.CustJobLabel)
projLabelLayout.addWidget(self.CustOrdLabel)
projLabelLayout.addWidget(self.ProductLabel)
summaryBoxLayout = QFormLayout(self.summaryBox)
summaryBoxLayout.setSpacing(1)
summaryBoxLayout.addRow(projLabelLayout)
summaryBoxLayout.addRow(projTextBoxesLayout)
app = QApplication(sys.argv)
main_window = WizAndChipsCal()
main_window.show()
app.exec_()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090326/97bfb5f2/attachment-0001.html
More information about the PyQt
mailing list