473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PyQt layout question: QScrollView and QGridLayout?

For a QApplication (PyQt) on the small screen of my Zaurus 5500 PDA I
try to layout my data output in a QScrollView as the central widget. I'd
prefer to use QGridLayout, but cannot add it to the scroll view.

sc=QScrollView(self)
layout=QGridLayout(..., sc.viewport())
sc.addChild(layout)

results in a TypeError.

Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.

Best wishes
Volker

--
Volker Lenhardt
E-Mail: vo*************@uni-duisburg-essen.de
Nov 22 '05 #1
10 5148
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
For a QApplication (PyQt) on the small screen of my Zaurus 5500 PDA I
try to layout my data output in a QScrollView as the central widget. I'd
prefer to use QGridLayout, but cannot add it to the scroll view.

sc=QScrollView(self)
layout=QGridLayout(..., sc.viewport())
sc.addChild(layout)

results in a TypeError.

Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.


QGridLayout is not a sub-class of QWidget, which is what addChild() is
expecting. You probably want QGrid.

Phil
Nov 22 '05 #2
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
For a QApplication (PyQt) on the small screen of my Zaurus 5500 PDA I
try to layout my data output in a QScrollView as the central widget. I'd
prefer to use QGridLayout, but cannot add it to the scroll view.

sc=QScrollView(self)
layout=QGridLayout(..., sc.viewport())
sc.addChild(layout)

results in a TypeError.

Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.


QGridLayout is not a sub-class of QWidget, which is what addChild() is
expecting. You probably want QGrid.

Phil
Nov 22 '05 #3
Phil Thompson schrieb:
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
prefer to use QGridLayout, but cannot add it to the scroll view.

sc=QScrollView(self)
layout=QGridLayout(..., sc.viewport())
sc.addChild(layout)

results in a TypeError.

Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.

QGridLayout is not a sub-class of QWidget, which is what addChild() is
expecting. You probably want QGrid.

Phil


I hoped to find a more assuring answer. There's no MultiCellWidget, no
Col/RowStretching, no Col/RowSpacing in QGrid. I've got to patch up one
VBox with a whole bunch of QV/QHBoxes and QGrids not to mention the
white space QLabels to fill not used grid cells.

And I have to delete all of them to change to another data layout.

Are you sure that there's no way to fill a QScrollView with the help of
some QLayout?

Still hopefully
Volker
Nov 22 '05 #4
Phil Thompson schrieb:
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
prefer to use QGridLayout, but cannot add it to the scroll view.

sc=QScrollView(self)
layout=QGridLayout(..., sc.viewport())
sc.addChild(layout)

results in a TypeError.

Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.

QGridLayout is not a sub-class of QWidget, which is what addChild() is
expecting. You probably want QGrid.

Phil


I hoped to find a more assuring answer. There's no MultiCellWidget, no
Col/RowStretching, no Col/RowSpacing in QGrid. I've got to patch up one
VBox with a whole bunch of QV/QHBoxes and QGrids not to mention the
white space QLabels to fill not used grid cells.

And I have to delete all of them to change to another data layout.

Are you sure that there's no way to fill a QScrollView with the help of
some QLayout?

Still hopefully
Volker
Nov 22 '05 #5
Volker Lenhardt wrote:
Phil Thompson schrieb:
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
prefer to use QGridLayout, but cannot add it to the scroll view.

sc=QScrollView(self)
layout=QGridLayout(..., sc.viewport())
sc.addChild(layout)

results in a TypeError.

Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.


QGridLayout is not a sub-class of QWidget, which is what addChild() is
expecting. You probably want QGrid.

Phil

I hoped to find a more assuring answer. There's no MultiCellWidget, no
Col/RowStretching, no Col/RowSpacing in QGrid. I've got to patch up one
VBox with a whole bunch of QV/QHBoxes and QGrids not to mention the
white space QLabels to fill not used grid cells.

And I have to delete all of them to change to another data layout.

Are you sure that there's no way to fill a QScrollView with the help of
some QLayout?

Still hopefully
Volker


I _think_ I have code that does waht you want. This creates multiple
layouts that contain an icon, a button, and some text on a scrollview.
The code is awkward and ugly, but it works.
class ScrollToolView(QScrollView):
def __init__(self,parent = None,name = None,fl = 0):
QScrollView.__init__(self,parent,name,fl)
self.items = {}
self.setStaticBackground(True)
self.enableClipper(True)

self.viewport().setPaletteBackgroundColor(qApp.pal ette().color(QPalette.Active,
QColorGroup.Background))
self.row_height = 120

def viewportResizeEvent(self, e):
for x in self.items:
self.items[x].resize(e.size().width(), self.row_height)

def addItem(self, name, title, pix, text, button_text, button_func):
num_items = len(self.items)
LayoutWidget = QWidget(self.viewport(),"layoutwidget")
LayoutWidget.setSizePolicy(QSizePolicy(QSizePolicy .Expanding,
QSizePolicy.Minimum))
LayoutWidget.setGeometry(QRect(0, 0, self.width(),
self.row_height))
self.addChild(LayoutWidget)

if num_items:
self.moveChild(LayoutWidget, 0, self.row_height*num_items)

layout = QGridLayout(LayoutWidget,1,1,10,10,"layout")

pushButton = QPushButton(LayoutWidget,"pushButton")

pushButton.setSizePolicy(QSizePolicy(QSizePolicy.M aximum,QSizePolicy.Fixed,0,0,

pushButton.sizePolicy().hasHeightForWidth()))
self.connect(pushButton,SIGNAL("clicked()"), button_func)

layout.addWidget(pushButton,2,2)

textLabel = QLabel(LayoutWidget,"textLabel")

layout.addWidget(textLabel,1,1)

pixmap = QLabel(LayoutWidget,"pixmapLabel2")

pixmap.setSizePolicy(QSizePolicy(QSizePolicy.Fixed ,QSizePolicy.Fixed,0,0,
pixmap.sizePolicy().hasHeightForWidth()))
pixmap.setMinimumSize(QSize(32,32))
pixmap.setMaximumSize(QSize(32,32))
pixmap.setPixmap(pix)
pixmap.setScaledContents(1)

layout.addWidget(pixmap,1,0)

textLabel2 = QLabel(LayoutWidget,"textLabel2")
textLabel2.setAlignment(QLabel.WordBreak | QLabel.AlignTop)

textLabel2.setSizePolicy(QSizePolicy(QSizePolicy.M inimum,QSizePolicy.Expanding))

layout.addWidget(textLabel2,2,1)

if num_items:
line = QFrame(LayoutWidget,"line")
line.setFrameShadow(QFrame.Sunken)
line.setFrameShape(QFrame.HLine)
layout.addMultiCellWidget(line,0,0,0,2)

textLabel.setText(title)
textLabel2.setText(text)
pushButton.setText(button_text)
self.resizeContents(self.width(), num_items*self.row_height*2)

LayoutWidget.show()

try:
self.items[name]
except KeyError:
self.items[name] = LayoutWidget
else:
print "ERROR: Duplicate button name:", name

def clear(self):
if len(self.items):
for x in self.items:
self.removeChild(self.items[x])
self.items[x].hide()

self.items.clear()
self.resizeContents(self.width(), 0)

-Don
Nov 22 '05 #6
Volker Lenhardt wrote:
Phil Thompson schrieb:
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
prefer to use QGridLayout, but cannot add it to the scroll view.

sc=QScrollView(self)
layout=QGridLayout(..., sc.viewport())
sc.addChild(layout)

results in a TypeError.

Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.


QGridLayout is not a sub-class of QWidget, which is what addChild() is
expecting. You probably want QGrid.

Phil

I hoped to find a more assuring answer. There's no MultiCellWidget, no
Col/RowStretching, no Col/RowSpacing in QGrid. I've got to patch up one
VBox with a whole bunch of QV/QHBoxes and QGrids not to mention the
white space QLabels to fill not used grid cells.

And I have to delete all of them to change to another data layout.

Are you sure that there's no way to fill a QScrollView with the help of
some QLayout?

Still hopefully
Volker


I _think_ I have code that does waht you want. This creates multiple
layouts that contain an icon, a button, and some text on a scrollview.
The code is awkward and ugly, but it works.
class ScrollToolView(QScrollView):
def __init__(self,parent = None,name = None,fl = 0):
QScrollView.__init__(self,parent,name,fl)
self.items = {}
self.setStaticBackground(True)
self.enableClipper(True)

self.viewport().setPaletteBackgroundColor(qApp.pal ette().color(QPalette.Active,
QColorGroup.Background))
self.row_height = 120

def viewportResizeEvent(self, e):
for x in self.items:
self.items[x].resize(e.size().width(), self.row_height)

def addItem(self, name, title, pix, text, button_text, button_func):
num_items = len(self.items)
LayoutWidget = QWidget(self.viewport(),"layoutwidget")
LayoutWidget.setSizePolicy(QSizePolicy(QSizePolicy .Expanding,
QSizePolicy.Minimum))
LayoutWidget.setGeometry(QRect(0, 0, self.width(),
self.row_height))
self.addChild(LayoutWidget)

if num_items:
self.moveChild(LayoutWidget, 0, self.row_height*num_items)

layout = QGridLayout(LayoutWidget,1,1,10,10,"layout")

pushButton = QPushButton(LayoutWidget,"pushButton")

pushButton.setSizePolicy(QSizePolicy(QSizePolicy.M aximum,QSizePolicy.Fixed,0,0,

pushButton.sizePolicy().hasHeightForWidth()))
self.connect(pushButton,SIGNAL("clicked()"), button_func)

layout.addWidget(pushButton,2,2)

textLabel = QLabel(LayoutWidget,"textLabel")

layout.addWidget(textLabel,1,1)

pixmap = QLabel(LayoutWidget,"pixmapLabel2")

pixmap.setSizePolicy(QSizePolicy(QSizePolicy.Fixed ,QSizePolicy.Fixed,0,0,
pixmap.sizePolicy().hasHeightForWidth()))
pixmap.setMinimumSize(QSize(32,32))
pixmap.setMaximumSize(QSize(32,32))
pixmap.setPixmap(pix)
pixmap.setScaledContents(1)

layout.addWidget(pixmap,1,0)

textLabel2 = QLabel(LayoutWidget,"textLabel2")
textLabel2.setAlignment(QLabel.WordBreak | QLabel.AlignTop)

textLabel2.setSizePolicy(QSizePolicy(QSizePolicy.M inimum,QSizePolicy.Expanding))

layout.addWidget(textLabel2,2,1)

if num_items:
line = QFrame(LayoutWidget,"line")
line.setFrameShadow(QFrame.Sunken)
line.setFrameShape(QFrame.HLine)
layout.addMultiCellWidget(line,0,0,0,2)

textLabel.setText(title)
textLabel2.setText(text)
pushButton.setText(button_text)
self.resizeContents(self.width(), num_items*self.row_height*2)

LayoutWidget.show()

try:
self.items[name]
except KeyError:
self.items[name] = LayoutWidget
else:
print "ERROR: Duplicate button name:", name

def clear(self):
if len(self.items):
for x in self.items:
self.removeChild(self.items[x])
self.items[x].hide()

self.items.clear()
self.resizeContents(self.width(), 0)

-Don
Nov 22 '05 #7
Volker Lenhardt wrote:
Phil Thompson schrieb:
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
[Using a QGridLayout in a QScrollView]
Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.


QGridLayout is not a sub-class of QWidget, which is what addChild() is
expecting. You probably want QGrid.


I hoped to find a more assuring answer. There's no MultiCellWidget, no
Col/RowStretching, no Col/RowSpacing in QGrid. I've got to patch up one
VBox with a whole bunch of QV/QHBoxes and QGrids not to mention the
white space QLabels to fill not used grid cells.


You can still use QGridLayout, but you need to put a widget into the
QScrollView in what the documentation describes as "Using One Big
Widget" (http://doc.trolltech.com/3.3/qscrollview.html).

Something along these lines should do basically what you want:

sv = QScrollView()
w = QWidget(sv.viewport())
sv.addChild(w)

grid = QGridLayout(w, 3, 3)

for i in range(0,3):
for j in range(0,3):
grid.addWidget(QLabel("(%i,%i)" % (i,j), w), i, j)

Of course, the widget that contains the layout is only as large as it
needs to be, so you may need to call its setMinimumSize() method if
you want it to be larger. However, it's often a better idea to ensure
that the child widgets have the sizes they need - their parent will
then be as large as they require.

Hope this helps,

David

Nov 22 '05 #8
Volker Lenhardt wrote:
Phil Thompson schrieb:
On Thursday 17 November 2005 2:56 pm, Volker Lenhardt wrote:
[Using a QGridLayout in a QScrollView]
Is there a way to get it to work? Filling a box viewport with lots of
padding boxes and white space labels to establish grids is very
cumbersome. And I need 4 different layouts to change places.


QGridLayout is not a sub-class of QWidget, which is what addChild() is
expecting. You probably want QGrid.


I hoped to find a more assuring answer. There's no MultiCellWidget, no
Col/RowStretching, no Col/RowSpacing in QGrid. I've got to patch up one
VBox with a whole bunch of QV/QHBoxes and QGrids not to mention the
white space QLabels to fill not used grid cells.


You can still use QGridLayout, but you need to put a widget into the
QScrollView in what the documentation describes as "Using One Big
Widget" (http://doc.trolltech.com/3.3/qscrollview.html).

Something along these lines should do basically what you want:

sv = QScrollView()
w = QWidget(sv.viewport())
sv.addChild(w)

grid = QGridLayout(w, 3, 3)

for i in range(0,3):
for j in range(0,3):
grid.addWidget(QLabel("(%i,%i)" % (i,j), w), i, j)

Of course, the widget that contains the layout is only as large as it
needs to be, so you may need to call its setMinimumSize() method if
you want it to be larger. However, it's often a better idea to ensure
that the child widgets have the sizes they need - their parent will
then be as large as they require.

Hope this helps,

David

Nov 22 '05 #9
Thank you Don, thank you David,

I was convinced that there must be a simple solution at hand. A dummy
widget!

It does work to my needs. Don's ScrollToolView is very interesting
though not yet the right tool for my actual application, but I've got
some more ideas for long winter nights ...

All the best
Volker
Nov 22 '05 #10
Thank you Don, thank you David,

I was convinced that there must be a simple solution at hand. A dummy
widget!

It does work to my needs. Don's ScrollToolView is very interesting
though not yet the right tool for my actual application, but I've got
some more ideas for long winter nights ...

All the best
Volker
Nov 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Vamsi Mudrageda | last post by:
I am kind of new to Python, and after trying and using wxPython, I found it kind of lacking in easy-to-read documentation, speed at loading, and GUI response-time. So I am looking for an another...
2
by: Konrad Koller | last post by:
For a card playing game I constructed a layout of 49 playing cards (size of each: x=71, y=96) which are arranged in a 7X7 matrix side by side. Accordingly the pysical size of the Canvas is x=71*7,...
0
by: Volker Lenhardt | last post by:
For a QApplication (PyQt) on the small screen of my Zaurus 5500 PDA I try to layout my data output in a QScrollView as the central widget. I'd prefer to use QGridLayout, but cannot add it to the...
0
by: Volker Lenhardt | last post by:
Once again a maybe silly question, but I find no solution, neither in the documentation nor in examples. I have got some different layouts to change place by the help of a QGridLayout in its...
4
by: gregarican | last post by:
I have an PyQt app were I need one of the windows to be able to be opened more than one at a time. When I try to open it I only get one instance at the same time. The main class is the QWidget()...
2
by: Svenn Bjerkem | last post by:
Hi, I am looking for a bit more elaboration on the problem of deleting elements from a QListsView. I know this is a tricky problem with references, but I have not been able to extract enough...
1
by: Felix Steffenhagen | last post by:
Hello, I have a problem with updating contents in a qscrollview. I've implementented two widgets (PremiseInput and PremiseList). You can find the source code under...
3
by: Marcpp | last post by:
Hi, I'm introducing to program in python + pyqt. I have a main window that call a second window (to introduce a info with textedit) when press the second window button I need to return to the main...
0
by: Samir Grover | last post by:
folks, I am trying put some user input fields into a scrollable (QScrollView) window. So, I placed a QLabel at 0,0 and QLineEdit at 0,1, next to QLabel. Somehow, results are not what I am...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.