473,605 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=QGridLay out(..., sc.viewport())
sc.addChild(lay out)

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 5173
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=QGridLay out(..., sc.viewport())
sc.addChild(lay out)

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=QGridLay out(..., sc.viewport())
sc.addChild(lay out)

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=QScrollVie w(self)
layout=QGridL ayout(..., sc.viewport())
sc.addChild(l ayout)

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=QScrollVie w(self)
layout=QGridL ayout(..., sc.viewport())
sc.addChild(l ayout)

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=QGridLay out(..., sc.viewport())
sc.addChild(lay out)

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,p arent = None,name = None,fl = 0):
QScrollView.__i nit__(self,pare nt,name,fl)
self.items = {}
self.setStaticB ackground(True)
self.enableClip per(True)

self.viewport() .setPaletteBack groundColor(qAp p.palette().col or(QPalette.Act ive,
QColorGroup.Bac kground))
self.row_height = 120

def viewportResizeE vent(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.vi ewport(),"layou twidget")
LayoutWidget.se tSizePolicy(QSi zePolicy(QSizeP olicy.Expanding ,
QSizePolicy.Min imum))
LayoutWidget.se tGeometry(QRect (0, 0, self.width(),
self.row_height ))
self.addChild(L ayoutWidget)

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

layout = QGridLayout(Lay outWidget,1,1,1 0,10,"layout")

pushButton = QPushButton(Lay outWidget,"push Button")

pushButton.setS izePolicy(QSize Policy(QSizePol icy.Maximum,QSi zePolicy.Fixed, 0,0,

pushButton.size Policy().hasHei ghtForWidth()))
self.connect(pu shButton,SIGNAL ("clicked()" ), button_func)

layout.addWidge t(pushButton,2, 2)

textLabel = QLabel(LayoutWi dget,"textLabel ")

layout.addWidge t(textLabel,1,1 )

pixmap = QLabel(LayoutWi dget,"pixmapLab el2")

pixmap.setSizeP olicy(QSizePoli cy(QSizePolicy. Fixed,QSizePoli cy.Fixed,0,0,
pixmap.sizePoli cy().hasHeightF orWidth()))
pixmap.setMinim umSize(QSize(32 ,32))
pixmap.setMaxim umSize(QSize(32 ,32))
pixmap.setPixma p(pix)
pixmap.setScale dContents(1)

layout.addWidge t(pixmap,1,0)

textLabel2 = QLabel(LayoutWi dget,"textLabel 2")
textLabel2.setA lignment(QLabel .WordBreak | QLabel.AlignTop )

textLabel2.setS izePolicy(QSize Policy(QSizePol icy.Minimum,QSi zePolicy.Expand ing))

layout.addWidge t(textLabel2,2, 1)

if num_items:
line = QFrame(LayoutWi dget,"line")
line.setFrameSh adow(QFrame.Sun ken)
line.setFrameSh ape(QFrame.HLin e)
layout.addMulti CellWidget(line ,0,0,0,2)

textLabel.setTe xt(title)
textLabel2.setT ext(text)
pushButton.setT ext(button_text )
self.resizeCont ents(self.width (), num_items*self. row_height*2)

LayoutWidget.sh ow()

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.removeChil d(self.items[x])
self.items[x].hide()

self.items.clea r()
self.resizeCont ents(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=QGridLay out(..., sc.viewport())
sc.addChild(lay out)

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,p arent = None,name = None,fl = 0):
QScrollView.__i nit__(self,pare nt,name,fl)
self.items = {}
self.setStaticB ackground(True)
self.enableClip per(True)

self.viewport() .setPaletteBack groundColor(qAp p.palette().col or(QPalette.Act ive,
QColorGroup.Bac kground))
self.row_height = 120

def viewportResizeE vent(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.vi ewport(),"layou twidget")
LayoutWidget.se tSizePolicy(QSi zePolicy(QSizeP olicy.Expanding ,
QSizePolicy.Min imum))
LayoutWidget.se tGeometry(QRect (0, 0, self.width(),
self.row_height ))
self.addChild(L ayoutWidget)

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

layout = QGridLayout(Lay outWidget,1,1,1 0,10,"layout")

pushButton = QPushButton(Lay outWidget,"push Button")

pushButton.setS izePolicy(QSize Policy(QSizePol icy.Maximum,QSi zePolicy.Fixed, 0,0,

pushButton.size Policy().hasHei ghtForWidth()))
self.connect(pu shButton,SIGNAL ("clicked()" ), button_func)

layout.addWidge t(pushButton,2, 2)

textLabel = QLabel(LayoutWi dget,"textLabel ")

layout.addWidge t(textLabel,1,1 )

pixmap = QLabel(LayoutWi dget,"pixmapLab el2")

pixmap.setSizeP olicy(QSizePoli cy(QSizePolicy. Fixed,QSizePoli cy.Fixed,0,0,
pixmap.sizePoli cy().hasHeightF orWidth()))
pixmap.setMinim umSize(QSize(32 ,32))
pixmap.setMaxim umSize(QSize(32 ,32))
pixmap.setPixma p(pix)
pixmap.setScale dContents(1)

layout.addWidge t(pixmap,1,0)

textLabel2 = QLabel(LayoutWi dget,"textLabel 2")
textLabel2.setA lignment(QLabel .WordBreak | QLabel.AlignTop )

textLabel2.setS izePolicy(QSize Policy(QSizePol icy.Minimum,QSi zePolicy.Expand ing))

layout.addWidge t(textLabel2,2, 1)

if num_items:
line = QFrame(LayoutWi dget,"line")
line.setFrameSh adow(QFrame.Sun ken)
line.setFrameSh ape(QFrame.HLin e)
layout.addMulti CellWidget(line ,0,0,0,2)

textLabel.setTe xt(title)
textLabel2.setT ext(text)
pushButton.setT ext(button_text )
self.resizeCont ents(self.width (), num_items*self. row_height*2)

LayoutWidget.sh ow()

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.removeChil d(self.items[x])
self.items[x].hide()

self.items.clea r()
self.resizeCont ents(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.view port())
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.view port())
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

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

Similar topics

35
7746
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 GUI toolkit that is cross-platform for Python, and am leaning toward PyQt (PyGTK is kind of dull looking in comparison). Unfortunately, although TrollTech says Qt is cross-platform, its license strategy has me a bit confused. So here is to...
2
2441
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, y=96*7: in the main program: canvas=QCanvas(497,672) class Board(QCanvasView): def __init__(self,canvas,parent): QCanvasView.__init__(self,canvas,parent)
0
487
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 scroll view. sc=QScrollView(self) layout=QGridLayout(..., sc.viewport()) sc.addChild(layout) results in a TypeError.
0
1247
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 parent widget. To make it nice I use row/col spacing and stretch respectively as well as multicell widgets. There is no problem if the layout next to come uses more rows and columns than the former one. But if it is the other way round, the grid...
4
6708
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() class with a QGridLayout() displaying the various window components. Is there a certain flag I need to set or different constructor I need to use to allow the window to be opened more than one at a time? Here's a brief snippet of the code that...
2
7039
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 knowledge from the documentation to solve a specific problem: In a dialog I have a QListView called referenceList. Entries are added and deleted from this list with buttons addButton and removeButton connected with sockets:
1
2008
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 http://www.informatik.uni-freiburg.de/~steffenh/premiseinput.{html|py} and http://www.informatik.uni-freiburg.de/~steffenh/premiselist.{html|py} The PremiseInput is a widget containing two QLineEdit's and a QComboBox. This widget should be showed in the PremiseList widget,...
3
3064
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 window the info introduced in the second window. I've seek in the pyqt doc examples but i don't find it. Have you any example?
0
993
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 expecting.It is placing QLineEdit below QLabel. I am not using designer for this. Please, notice that I convert vbox's box layout into
0
7934
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8425
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8288
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1271
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.