[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] my program is ignoring setgeometry and the form
From: Michael Staggs <tausciam () gmail ! com>
Date: 2013-08-19 23:47:01
Message-ID: 3395258.JkFlAdN3s4 () tannhaus-pc
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I have my program:
1. from PyQt4.QtCore[1] import *
2. from PyQt4.QtGui[2] import *
3. from window import Ui_MainWindow
4.
5. THUMBNAIL_SIZE = 128
6. SPACING = 10
7. IMAGES_PER_ROW = 5
8.
9. class TableWidget(QTableWidget[3]):
10. def __init__(self, parent=None, **kwargs):
11. _QTableWidget_.__init__(self, parent, **kwargs)
12.
13. self.setIconSize(QSize[4](128,128))
14. self.setColumnCount(IMAGES_PER_ROW)
15. self.setGridStyle(Qt[5].NoPen)
16.
17. # Set the default column width and hide the header
18. self.verticalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)
19. self.verticalHeader().hide()
20.
21. # Set the default row height and hide the header
22. self.horizontalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)
23. self.horizontalHeader().hide()
24.
25. # Set the table width to show all images without horizontal scrolling
26.
self.setMinimumWidth((THUMBNAIL_SIZE+SPACING)*IMAGES_PER_ROW+(SPACING*2))
27.
28. def addPicture(self, row, col, picturePath):
29. item=QTableWidgetItem[6]()
30.
31. # Scale the image by either height or width and then 'crop' it to the
32. # desired size, this prevents distortion of the image.
33. p=QPixmap[7](picturePath)
34. if p.height()>p.width(): p=p.scaledToWidth(THUMBNAIL_SIZE)
35. else: p=p.scaledToHeight(THUMBNAIL_SIZE)
36. p=p.copy(0,0,THUMBNAIL_SIZE,THUMBNAIL_SIZE)
37. item.setIcon(QIcon[8](p))
38.
39. self.setItem(row,col,item)
40.
41. class MainWindow(QMainWindow[9], Ui_MainWindow):
42. def __init__(self, parent=None, **kwargs):
43. super(MainWindow, self).__init__(parent)
44. self.setupUi(self)
45.
46. centralWidget=QWidget[10](self)
47. l=QVBoxLayout[11](centralWidget)
48.
49. self.tableWidget=TableWidget(self)
50. l.addWidget(self.tableWidget)
51.
52. self.setCentralWidget(centralWidget)
53.
54.
picturesPath=QDesktopServices[12].storageLocation(_QDesktopServices_.PicturesLocation
)
55. pictureDir=QDir[13](picturesPath)
56. pictures=pictureDir.entryList(['*.jpg','*.png','*.gif'])
57.
58. rowCount=len(pictures)//IMAGES_PER_ROW
59. if len(pictures)%IMAGES_PER_ROW: rowCount+=1
60. self.tableWidget.setRowCount(rowCount)
61.
62. row=-1
63. for i,picture in enumerate(pictures):
64. col=i%IMAGES_PER_ROW
65. if not col: row+=1
66. self.tableWidget.addPicture(row, col, pictureDir.absoluteFilePath(picture))
67.
68. if __name__=="__main__":
69. from sys import argv, exit
70.
71. a=QApplication[14](argv)
72. m=MainWindow()
73. m.show()
74. m.raise_()
75. exit(a.exec_())
and I have my gui file I got by designing the form using QT Designer then running pyuic4:
1. # -*- coding: utf-8 -*-
2.
3. # Form implementation generated from reading ui file 'window.ui'
4. #
5. # Created by: PyQt4 UI code generator 4.9.6
6. #
7. # WARNING! All changes made in this file will be lost!
8.
9. from PyQt4 import QtCore[1], QtGui[2]
10.
11. try:
12. _fromUtf8 = QtCore[1].QString[15].fromUtf8
13. except AttributeError:
14. def _fromUtf8(s):
15. return s
16.
17. try:
18. _encoding = QtGui[2].QApplication[14].UnicodeUTF8
19. def _translate(context, text, disambig):
20. return QtGui[2].QApplication[14].translate(context, text, disambig, _encoding)
21. except AttributeError:
22. def _translate(context, text, disambig):
23. return QtGui[2].QApplication[14].translate(context, text, disambig)
24.
25. class Ui_MainWindow(object):
26. def setupUi(self, MainWindow):
27. MainWindow.setObjectName(_fromUtf8("MainWindow"))
28. MainWindow.resize(800, 600)
29. self.centralwidget = QtGui[2].QWidget[10](MainWindow)
30. self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
31. self.tableWidget = QtGui[2].QTableWidget[3](self.centralwidget)
32. self.tableWidget.setGeometry(QtCore[1].QRect[16](70, 20, 661, 381))
33. self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
34. self.tableWidget.setColumnCount(0)
35. self.tableWidget.setRowCount(0)
36. self.listWidget = QtGui[2].QListWidget[17](self.centralwidget)
37. self.listWidget.setGeometry(QtCore[1].QRect[16](70, 400, 661, 181))
38. self.listWidget.setObjectName(_fromUtf8("listWidget"))
39. MainWindow.setCentralWidget(self.centralwidget)
40.
41. self.retranslateUi(MainWindow)
42. QtCore[1].QMetaObject[18].connectSlotsByName(MainWindow)
43.
44. def retranslateUi(self, MainWindow):
45. MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
According to the websites I've read, I've done what needs to be done to link the two. I
added
1. from window import Ui_MainWindow
2. class MainWindow(QMainWindow[9], Ui_MainWindow):
3. def __init__(self, parent=None, **kwargs):
4. super(MainWindow, self).__init__(parent)
5. self.setupUi(self)
I thought the tablewidget from my program would be mapped onto my window.py form I
created. However, it does no such thing. It totally ignores the form except for setting the
title and geometry of the main window. Then, it acts like I don't even have a window.py
What am I doing wrong? Right now, I'm using my pictures directory for a working example.
Eventually, I want to display album covers in the top window, click on the album cover, and
display the songs in the bottom window. I thought about using a dict where the album is
the key and the list of songs is the value in order to do that. However, it's totally ignoring
my form.
Here is a picture of the form as it should be:
http://i.imgur.com/Wrp1zHW.png[19]
The program should, at this point, be displaying all my pictures in that top window.
However, this is what happens when I run it:
[Attachment #5 (unknown)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" \
content="1" /><style type="text/css"> p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; \
font-weight:400; font-style:normal;"> <p style=" margin-top:12px; margin-bottom:12px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">I have my program: </p> <ol style="margin-top: 0px; margin-bottom: \
0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">from PyQt4.<a \
href="http://qt-project.org/doc/QtCore.html"><span style=" text-decoration: \
underline; color:#006e28;">QtCore</span></a> import *</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">from PyQt4.<a \
href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: underline; \
color:#006e28;">QtGui</span></a> import *</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">from window import Ui_MainWindow</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">THUMBNAIL_SIZE = 128</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">SPACING = 10</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">IMAGES_PER_ROW = 5</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">class TableWidget(<a \
href="http://qt-project.org/doc/QTableWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QTableWidget</span></a>):</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> def __init__(self, parent=None, \
**kwargs):</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
<a href="http://qt-project.org/doc/QTableWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QTableWidget</span></a>.__init__(self, parent, \
**kwargs)</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setIconSize(<a href="http://qt-project.org/doc/QSize.html"><span style=" \
text-decoration: underline; color:#006e28;">QSize</span></a>(128,128))</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setColumnCount(IMAGES_PER_ROW)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> self.setGridStyle(<a \
href="http://qt-project.org/doc/Qt.html"><span style=" text-decoration: underline; \
color:#006e28;">Qt</span></a>.NoPen)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> # Set the default column width and \
hide the header</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.verticalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.verticalHeader().hide()</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> </li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> # Set the default row height and hide the header</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.horizontalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.horizontalHeader().hide()</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> </li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> # Set the table width to show all images without \
horizontal scrolling</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> \
self.setMinimumWidth((THUMBNAIL_SIZE+SPACING)*IMAGES_PER_ROW+(SPACING*2))</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> def addPicture(self, \
row, col, picturePath):</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> item=<a \
href="http://qt-project.org/doc/QTableWidgetItem.html"><span style=" text-decoration: \
underline; color:#006e28;">QTableWidgetItem</span></a>()</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> # Scale the image \
by either height or width and then 'crop' it to the</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> # desired size, this prevents \
distortion of the image.</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> p=<a \
href="http://qt-project.org/doc/QPixmap.html"><span style=" text-decoration: \
underline; color:#006e28;">QPixmap</span></a>(picturePath)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> if \
p.height()>p.width(): p=p.scaledToWidth(THUMBNAIL_SIZE)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> else: \
p=p.scaledToHeight(THUMBNAIL_SIZE)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> \
p=p.copy(0,0,THUMBNAIL_SIZE,THUMBNAIL_SIZE)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> item.setIcon(<a \
href="http://qt-project.org/doc/QIcon.html"><span style=" text-decoration: underline; \
color:#006e28;">QIcon</span></a>(p))</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> self.setItem(row,col,item)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">class MainWindow(<a \
href="http://qt-project.org/doc/QMainWindow.html"><span style=" text-decoration: \
underline; color:#006e28;">QMainWindow</span></a>, Ui_MainWindow):</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> def __init__(self, \
parent=None, **kwargs):</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> super(MainWindow, self).__init__(parent)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setupUi(self)</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> </li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> centralWidget=<a \
href="http://qt-project.org/doc/QWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QWidget</span></a>(self)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> l=<a \
href="http://qt-project.org/doc/QVBoxLayout.html"><span style=" text-decoration: \
underline; color:#006e28;">QVBoxLayout</span></a>(centralWidget)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.tableWidget=TableWidget(self)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> l.addWidget(self.tableWidget)</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setCentralWidget(centralWidget)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> picturesPath=<a \
href="http://qt-project.org/doc/QDesktopServices.html"><span style=" text-decoration: \
underline; color:#006e28;">QDesktopServices</span></a>.storageLocation(<a \
href="http://qt-project.org/doc/QDesktopServices.html"><span style=" text-decoration: \
underline; color:#006e28;">QDesktopServices</span></a>.PicturesLocation)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> pictureDir=<a \
href="http://qt-project.org/doc/QDir.html"><span style=" text-decoration: underline; \
color:#006e28;">QDir</span></a>(picturesPath)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> \
pictures=pictureDir.entryList(['*.jpg','*.png','*.gif'])</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
rowCount=len(pictures)//IMAGES_PER_ROW</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> if len(pictures)%IMAGES_PER_ROW: \
rowCount+=1</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.tableWidget.setRowCount(rowCount)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> row=-1</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> for i,picture in \
enumerate(pictures):</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> col=i%IMAGES_PER_ROW</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> if not col: \
row+=1</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.tableWidget.addPicture(row, col, pictureDir.absoluteFilePath(picture)) \
</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">if \
__name__=="__main__":</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> from sys import argv, exit</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> a=<a \
href="http://qt-project.org/doc/QApplication.html"><span style=" text-decoration: \
underline; color:#006e28;">QApplication</span></a>(argv)</li> <li style=" \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> m.show()</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> m.raise_()</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
exit(a.exec_())</li></ol> <p style=" margin-top:12px; margin-bottom:12px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">and I have my gui file I got by designing the form using QT \
Designer then running pyuic4: </p> <ol style="margin-top: 0px; margin-bottom: 0px; \
margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"># -*- coding: utf-8 -*-</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"># Form implementation \
generated from reading ui file 'window.ui'</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">#</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"># Created by: PyQt4 UI code generator 4.9.6</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">#</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"># WARNING! All changes made \
in this file will be lost!</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> </li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">from PyQt4 import <a \
href="http://qt-project.org/doc/QtCore.html"><span style=" text-decoration: \
underline; color:#006e28;">QtCore</span></a>, <a \
href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: underline; \
color:#006e28;">QtGui</span></a></li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> </li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">try:</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> _fromUtf8 = <a \
href="http://qt-project.org/doc/QtCore.html"><span style=" text-decoration: \
underline; color:#006e28;">QtCore</span></a>.<a \
href="http://qt-project.org/doc/QString.html"><span style=" text-decoration: \
underline; color:#006e28;">QString</span></a>.fromUtf8</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">except AttributeError:</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> def _fromUtf8(s):</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> return s</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">try:</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> _encoding = <a \
href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: underline; \
color:#006e28;">QtGui</span></a>.<a \
href="http://qt-project.org/doc/QApplication.html"><span style=" text-decoration: \
underline; color:#006e28;">QApplication</span></a>.UnicodeUTF8</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> def _translate(context, \
text, disambig):</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
return <a href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: \
underline; color:#006e28;">QtGui</span></a>.<a \
href="http://qt-project.org/doc/QApplication.html"><span style=" text-decoration: \
underline; color:#006e28;">QApplication</span></a>.translate(context, text, disambig, \
_encoding)</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">except \
AttributeError:</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> def \
_translate(context, text, disambig):</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> return <a \
href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: underline; \
color:#006e28;">QtGui</span></a>.<a \
href="http://qt-project.org/doc/QApplication.html"><span style=" text-decoration: \
underline; color:#006e28;">QApplication</span></a>.translate(context, text, \
disambig)</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">class \
Ui_MainWindow(object):</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> def setupUi(self, MainWindow):</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
MainWindow.setObjectName(_fromUtf8("MainWindow"))</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
MainWindow.resize(800, 600)</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> self.centralwidget = <a \
href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: underline; \
color:#006e28;">QtGui</span></a>.<a \
href="http://qt-project.org/doc/QWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QWidget</span></a>(MainWindow)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> self.tableWidget \
= <a href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: \
underline; color:#006e28;">QtGui</span></a>.<a \
href="http://qt-project.org/doc/QTableWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QTableWidget</span></a>(self.centralwidget)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.tableWidget.setGeometry(<a href="http://qt-project.org/doc/QtCore.html"><span \
style=" text-decoration: underline; color:#006e28;">QtCore</span></a>.<a \
href="http://qt-project.org/doc/QRect.html"><span style=" text-decoration: underline; \
color:#006e28;">QRect</span></a>(70, 20, 661, 381))</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> \
self.tableWidget.setObjectName(_fromUtf8("tableWidget"))</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.tableWidget.setColumnCount(0)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> self.tableWidget.setRowCount(0)</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> self.listWidget = \
<a href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: \
underline; color:#006e28;">QtGui</span></a>.<a \
href="http://qt-project.org/doc/QListWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QListWidget</span></a>(self.centralwidget)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.listWidget.setGeometry(<a href="http://qt-project.org/doc/QtCore.html"><span \
style=" text-decoration: underline; color:#006e28;">QtCore</span></a>.<a \
href="http://qt-project.org/doc/QRect.html"><span style=" text-decoration: underline; \
color:#006e28;">QRect</span></a>(70, 400, 661, 181))</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> \
self.listWidget.setObjectName(_fromUtf8("listWidget"))</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
MainWindow.setCentralWidget(self.centralwidget)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> self.retranslateUi(MainWindow)</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> <a \
href="http://qt-project.org/doc/QtCore.html"><span style=" text-decoration: \
underline; color:#006e28;">QtCore</span></a>.<a \
href="http://qt-project.org/doc/QMetaObject.html"><span style=" text-decoration: \
underline; color:#006e28;">QMetaObject</span></a>.connectSlotsByName(MainWindow)</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> def retranslateUi(self, \
MainWindow):</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", \
None))</li></ol> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">According \
to the websites I've read, I've done what needs to be done to link the two. I added \
</p> <ol style="margin-top: 0px; margin-bottom: 0px; margin-right: 0px; \
-qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">from window \
import Ui_MainWindow</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">class MainWindow(<a \
href="http://qt-project.org/doc/QMainWindow.html"><span style=" text-decoration: \
underline; color:#006e28;">QMainWindow</span></a>, Ui_MainWindow):</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> def __init__(self, \
parent=None, **kwargs):</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> super(MainWindow, self).__init__(parent)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setupUi(self)</li></ol> <p style=" margin-top:12px; margin-bottom:12px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">I thought the tablewidget from my program would be mapped onto my \
window.py form I created. However, it does no such thing. It totally ignores the form \
except for setting the title and geometry of the main window. Then, it acts like I \
don't even have a window.py </p> <p style=" margin-top:12px; margin-bottom:12px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">What am I doing wrong? Right now, I'm using my pictures directory \
for a working example. Eventually, I want to display album covers in the top window, \
click on the album cover, and display the songs in the bottom window. I thought about \
using a dict where the album is the key and the list of songs is the value in order \
to do that. However, it's totally ignoring my form.</p> <p style=" margin-top:12px; \
margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">Here is a picture of the form as it should be: \
</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><a \
href="http://i.imgur.com/Wrp1zHW.png"><span style=" text-decoration: underline; \
color:#006e28;">http://i.imgur.com/Wrp1zHW.png</span></a> </p> <p style=" \
margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">The program should, at this \
point, be displaying all my pictures in that top window. However, this is what \
happens when I run it: </p> <p style=" margin-top:12px; margin-bottom:12px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"><a href="http://i.imgur.com/ZQfsMDa.png"><span style=" \
text-decoration: underline; color:#006e28;">http://i.imgur.com/ZQfsMDa.png</span></a> \
</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">I have made \
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><a \
href="http://i.imgur.com/x7VoIbd.png"><span style=" text-decoration: underline; \
color:#006e28;">http://i.imgur.com/x7VoIbd.png</span></a> </p> <p style=" \
margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">However, the boxes go from \
side to side completely and don't have the extra space on the sides I wanted and, \
when I change the gui, it won't be so simple to change it. I'd like to learn how to \
incorporate the file properly. </p> <ol style="margin-top: 0px; margin-bottom: 0px; \
margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">from PyQt4.<a \
href="http://qt-project.org/doc/QtCore.html"><span style=" text-decoration: \
underline; color:#006e28;">QtCore</span></a> import *</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">from PyQt4.<a \
href="http://qt-project.org/doc/QtGui.html"><span style=" text-decoration: underline; \
color:#006e28;">QtGui</span></a> import *</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">THUMBNAIL_SIZE = 128</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">SPACING = 10</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">IMAGES_PER_ROW = 5</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">class MainWindow(<a \
href="http://qt-project.org/doc/QMainWindow.html"><span style=" text-decoration: \
underline; color:#006e28;">QMainWindow</span></a>):</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> def __init__(self, parent=None, \
**kwargs):</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
<a href="http://qt-project.org/doc/QMainWindow.html"><span style=" text-decoration: \
underline; color:#006e28;">QMainWindow</span></a>.__init__(self, parent, \
**kwargs)</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.resize(800,600)</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> self.setWindowTitle("Image Gallery")</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> centralWidget=<a \
href="http://qt-project.org/doc/QWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QWidget</span></a>(self)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> l=<a \
href="http://qt-project.org/doc/QVBoxLayout.html"><span style=" text-decoration: \
underline; color:#006e28;">QVBoxLayout</span></a>(centralWidget)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.tableWidget=TableWidget(self)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> l.addWidget(self.tableWidget)</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.listWidget=ListWidget(self)</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> l.addWidget(self.listWidget)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setCentralWidget(centralWidget)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> picturesPath=<a \
href="http://qt-project.org/doc/QDesktopServices.html"><span style=" text-decoration: \
underline; color:#006e28;">QDesktopServices</span></a>.storageLocation(<a \
href="http://qt-project.org/doc/QDesktopServices.html"><span style=" text-decoration: \
underline; color:#006e28;">QDesktopServices</span></a>.PicturesLocation)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> pictureDir=<a \
href="http://qt-project.org/doc/QDir.html"><span style=" text-decoration: underline; \
color:#006e28;">QDir</span></a>(picturesPath)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> \
pictures=pictureDir.entryList(['*.jpg','*.png','*.gif'])</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
rowCount=len(pictures)//IMAGES_PER_ROW</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> if len(pictures)%IMAGES_PER_ROW: \
rowCount+=1</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.tableWidget.setRowCount(rowCount)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> row=-1</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> for i,picture in \
enumerate(pictures):</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> col=i%IMAGES_PER_ROW</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> if not col: \
row+=1</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.tableWidget.addPicture(row, col, pictureDir.absoluteFilePath(picture)) \
</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">class ListWidget(<a \
href="http://qt-project.org/doc/QListWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QListWidget</span></a>):</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> def __init__(self, parent=MainWindow, \
**kwargs):</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
<a href="http://qt-project.org/doc/QListWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QListWidget</span></a>.__init__(self, parent, \
**kwargs)</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setGeometry(<a href="http://qt-project.org/doc/QRect.html"><span style=" \
text-decoration: underline; color:#006e28;">QRect</span></a>(70, 400, 661, 181))</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">class TableWidget(<a \
href="http://qt-project.org/doc/QTableWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QTableWidget</span></a>):</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> def __init__(self, parent=MainWindow, \
**kwargs):</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
<a href="http://qt-project.org/doc/QTableWidget.html"><span style=" text-decoration: \
underline; color:#006e28;">QTableWidget</span></a>.__init__(self, parent, \
**kwargs)</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setIconSize(<a href="http://qt-project.org/doc/QSize.html"><span style=" \
text-decoration: underline; color:#006e28;">QSize</span></a>(128,128))</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.setColumnCount(IMAGES_PER_ROW)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> self.setGridStyle(<a \
href="http://qt-project.org/doc/Qt.html"><span style=" text-decoration: underline; \
color:#006e28;">Qt</span></a>.NoPen)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> self.setGeometry(<a \
href="http://qt-project.org/doc/QRect.html"><span style=" text-decoration: underline; \
color:#006e28;">QRect</span></a>(70, 20, 661, 381)) </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> # Set the default \
column width and hide the header</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> \
self.verticalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.verticalHeader().hide()</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> </li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> # Set the default row height and hide the header</li> \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.horizontalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
self.horizontalHeader().hide()</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> </li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> # Set the table width to show all images without \
horizontal scrolling</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"># \
self.setMinimumWidth((THUMBNAIL_SIZE+SPACING)*IMAGES_PER_ROW+(SPACING*2))</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> def addPicture(self, \
row, col, picturePath):</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> item=<a \
href="http://qt-project.org/doc/QTableWidgetItem.html"><span style=" text-decoration: \
underline; color:#006e28;">QTableWidgetItem</span></a>()</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> # Scale the image \
by either height or width and then 'crop' it to the</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> p=<a \
href="http://qt-project.org/doc/QPixmap.html"><span style=" text-decoration: \
underline; color:#006e28;">QPixmap</span></a>(picturePath)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> if \
p.height()>p.width(): p=p.scaledToWidth(THUMBNAIL_SIZE)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> else: \
p=p.scaledToHeight(THUMBNAIL_SIZE)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> \
p=p.copy(0,0,THUMBNAIL_SIZE,THUMBNAIL_SIZE)</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> item.setIcon(<a \
href="http://qt-project.org/doc/QIcon.html"><span style=" text-decoration: underline; \
color:#006e28;">QIcon</span></a>(p))</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> self.setItem(row,col,item)</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> </li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">if \
__name__=="__main__":</li> <li style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"> from sys import argv, exit</li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> </li> <li style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"> a=<a \
href="http://qt-project.org/doc/QApplication.html"><span style=" text-decoration: \
underline; color:#006e28;">QApplication</span></a>(argv)</li> <li style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> m=MainWindow()</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> m.show()</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> m.raise_()</li> <li \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"> \
exit(a.exec_())</li></ol> <p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; "> </p> <p style=" margin-top:0px; margin-bottom:12px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">Working further with it and adding pushbuttons, the two boxes \
ignoring their geometry means the pushbuttons get added ON TOP OF the boxes instead \
of beside them. </p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><a \
href="http://i.imgur.com/19ZMm7y.png"><span style=" text-decoration: underline; \
color:#006e28;">http://i.imgur.com/19ZMm7y.png</span></a> </p> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p></body></html>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic