[PyKDE] Geometry management

Boudewijn Rempt boud at rempt.xs4all.nl
Wed Sep 29 07:38:53 BST 1999


Well, I guess I'm the first to open the list... Hello, all!

I've recently been toying with geometry management, which appears to
be pretty mandatory for KDE, and I found some strange things. Does
anyone know why, when I set the minimumsize of one of the widgets in a
gridlayout, setting the minimumsize of my dialog doesn't work anymore? 
Try removing the comment at line 40.

Is there anyone who has more experience with geometry management? It's
rather difficult to layout nice dialogs - what I generally do is using
QtArch to layout the thing, and translate the result to Python.

I have the small example script attached...

Boudewijn Rempt  | http://www.xs4all.nl/~bsarempt
-------------- next part --------------
TRUE=1
FALSE=0

#
# Status bar
#
ID_HINTTEXT = 1

#
# Toolbar
#
TB_NEW      = 1
TB_OPEN     = 2
TB_EXIT     = 3

-------------- next part --------------
#!/usr/bin/env python

#
# Multi-row view of selected items from the lng_lex table
#

import sys

from qt import *
from kdecore import *
from kdeui import *

from constants import *

ID_HINTTEXT=1
TB_SEARCH=1

class srchLex(QDialog):
  
  def __init__(self, parent, title):
    QDialog.__init__(self, parent, "Search", TRUE, WStyle_DialogBorder)

    self.setCaption("Search Criteria")

    self.frame=QFrame(self, "frame")
    self.frame.setFrameStyle(35)
    self.frame.setLineWidth(2)
    self.frame.setMidLineWidth(0)
    self.frame.setMargin(20)

    self.bnOK=QPushButton(i18n("&OK"),self)
    self.bnOK.setDefault(TRUE)
    QObject.connect(self.bnOK, SIGNAL("clicked()"), self.slotAccept)
    
    self.bnCancel=QPushButton(i18n("&Cancel"),self)
    QObject.connect(self.bnCancel, SIGNAL("clicked()"), self.slotReject)

    self.txtForm=QLineEdit(self.frame)
    self.lblForm=QLabel(self.txtForm, "&Form",self.frame)
    #self.lblForm.setMinimumSize(self.lblForm.sizeHint())

    self.topLayout=QBoxLayout(self, QBoxLayout.Direction.LeftToRight, 10, 5, None)
    self.topLayout.addStrut(1)
    self.topLayout.addWidget(self.frame, 3, 36)

    self.fieldLayout=QGridLayout(self.frame, 3, 4, 5, 5, None)
    
    self.fieldLayout.addColSpacing(0,5)
    self.fieldLayout.addColSpacing(1,5)
    self.fieldLayout.addColSpacing(2,5)
    self.fieldLayout.addColSpacing(3,5)
    
    self.fieldLayout.setColStretch(0,0)
    self.fieldLayout.setColStretch(1,1)
    self.fieldLayout.setColStretch(2,3)
    self.fieldLayout.setColStretch(3,0)
    
    self.fieldLayout.addRowSpacing(0,0)
    self.fieldLayout.setRowStretch(0,0)
    
    self.fieldLayout.addWidget(self.lblForm, 1, 1, 33)
    self.fieldLayout.addWidget(self.txtForm, 1, 2, 36)
    self.fieldLayout.addRowSpacing(1,0)
    self.fieldLayout.setRowStretch(1,1)

    self.fieldLayout.addRowSpacing(2,0)
    self.fieldLayout.setRowStretch(2,0)    

    self.buttonLayout = QBoxLayout(QBoxLayout.Direction.TopToBottom, 5, None)
    self.topLayout.addLayout(self.buttonLayout, 1)
    self.buttonLayout.addStrut(1)
    self.buttonLayout.addWidget(self.bnOK,1,36)
    self.buttonLayout.addWidget(self.bnCancel, 1, 36)
    self.buttonLayout.addStretch(6)

    self.resize(550, 230)
    self.setMinimumSize( 550, 230 )
    self.setMaximumSize( 32767, 32767 )

    self.txtForm.setFocus()
        
  def slotAccept(self):
    self.accept() 
          
  def slotReject(self):
    self.reject()
    
class recLex(QDialog):

  def __init__(self, parent, title,  lexnr=None):
    pass
    
class mrLex(QListView):

#
# This initialises the listview
#

  def __init__(self, parent, languagenr=1):
    QListView.__init__(self, parent)

class Win(KTMainWindow):

  def __init__(self, *args):
    apply(KTMainWindow.__init__,(self,)+args)
    
    self.file=QPopupMenu()
    self.file.insertItem(i18n("&Search"),self.slotSearch, CTRL+Key_S)
    
    self.menu=KMenuBar(self)
    self.menu.insertItem(i18n("&File"), self.file)
    self.menu.show()
    self.setMenu(self.menu)  

    self.toolbar=KToolBar(self)
    self.toolbar.insertButton(Icon("search.xpm"), TB_SEARCH, TRUE
                             ,i18n("Search")
                             )
    self.addToolBar(self.toolbar)
    self.toolbar.show()
    self.connect(self.toolbar
                ,SIGNAL("clicked(int)")
                ,self.commandCallback
                )
                             
    self.statusbar=KStatusBar(self)
    self.statusbar.insertItem("Welcome to Kura",ID_HINTTEXT)
    self.statusbar.show()
    self.setStatusBar(self.statusbar)

    self.view=mrLex(self)
    self.setView(self.view)
    self.view.show()
    #
    # Important! Otherwise the focus will be on the app, instead of
    # the listview and users will be no end confused when they can't
    # use the keyboard to navigate the list.
    #
    self.view.setFocus()
    
  def closeEvent(self, QCloseEvent):
    QCloseEvent.accept()
    
  def slotSearch(self):

    dlgSrch=srchLex(self, "Search")
    dlgSrch.exec_loop()
    
  def commandCallback(self, item):
    if item==TB_SEARCH:
      self.slotSearch()
                             
def main():
  app=KApplication(sys.argv,"lex")
  toplevel=Win()
  app.setMainWidget(toplevel)
  toplevel.show()
  app.exec_loop()
  
if __name__=="__main__":
  main()



More information about the PyQt mailing list