[PyKDE] Problem in showing the toolbar

cheng cheng at innoverse.com
Thu Oct 11 21:41:25 BST 2001


Thank you for the reply of QStatusBar problem.  Now I can remove the
 statusbar perfectly.
 For the toolbar problem, if I put these code
"self.fileTools = QToolBar(self,'file operations')
 self.openIcon = QPixmap(fileopen)
 self.fileOpen = QToolButton(self.openIcon,'Open
File',QString.null,self.bold,self.fileTools,'open file')
 self.fileOpen.setAutoRaise( TRUE )"

 in "def __init__( self )", it works.  However, if I put the codes in "def
standard( self )", it doesn't work.

 Thank you.

 Cheng



 Following is my code:

 #!/usr/bin/env python

 import sys, string
 from qt import *

 TRUE  = 1
 FALSE = 0

 fileopen = [
 '    16    13        5            1',
 '. c #040404',
 '# c #808304',
 'a c None',
 'b c #f3f704',
 'c c #f3f7f3',
 'aaaaaaaaa...aaaa',
 'aaaaaaaa.aaa.a.a',
 'aaaaaaaaaaaaa..a',
 'a...aaaaaaaa...a',
 '.bcb.......aaaaa',
 '.cbcbcbcbc.aaaaa',
 '.bcbcbcbcb.aaaaa',
 '.cbcb...........',
 '.bcb.#########.a',
 '.cb.#########.aa',
 '.b.#########.aaa',
 '..#########.aaaa',
 '...........aaaaa'
 ]


 class MenuExample( QMainWindow ):
   def __init__( self ):
       QMainWindow.__init__(self,None, 'example application main window',
 Qt.WDestructiveClose)

       self.toolbar = QPopupMenu( self )
       self.standardID = self.toolbar.insertItem( "Standard Buttons" )
       self.toolbar.connectItem( self.standardID, self.standard )
       self.EliminateID = self.toolbar.insertItem( "'Eliminate' Buttons" )
       self.toolbar.connectItem( self.EliminateID, self.eliminateButton )

       self.isEliminate = FALSE
       self.isStandard = FALSE
       self.toolbar.setCheckable( TRUE )

       self.view = QPopupMenu( self )
       #CHECK_PTR( self.options )
       self.menuBar().insertItem ( "View", self.view )
       self.view.insertItem( "Toolbars",  self.toolbar )
       self.barID = self.view.insertItem( "Status Bar" )
       self.view.connectItem( self.barID, self.statusbar )

       self.isBar = FALSE
       self.view.setCheckable( TRUE )

       self.e = QMultiLineEdit( self, 'editor' )
       self.e.setFocus()
       self.setCentralWidget(self.e)

       self.resize(600,350)
       self.setMinimumSize( 620, 330 )

   def statusbar( self ):
     self.isBar = not self.isBar
     self.view.setItemChecked( self.barID, self.isBar )
     if self.isBar == TRUE:
       self.statusBar().message('Ready',2000)
     elif self.isBar == FALSE:
       self.statusBar().parent().removeChild(self.statusBar())

   def standard( self ):
     self.isStandard = not self.isStandard
     self.toolbar.setItemChecked( self.standardID, self.isStandard )

     self.fileTools = QToolBar(self,'file operations')

     self.openIcon = QPixmap(fileopen)
     self.fileOpen = QToolButton(self.openIcon,'Open

 File',QString.null,self.bold,self.fileTools,'open file')
     self.fileOpen.setAutoRaise( TRUE )


   def eliminateButton( self ):
     self.isEliminate = not self.isEliminate
     self.toolbar.setItemChecked( self.EliminateID, self.isEliminate )
     self.emit ( PYSIGNAL( "explain" ), ( "standard", ) )

   def bold( self ):
     self.isBold = not self.isBold
     self.view.setItemChecked( self.boldID, self.isBold )
     self.emit ( PYSIGNAL( "explain" ), ( "view/Bold selected", ) )

 a = QApplication( sys.argv )
 m = MenuExample()
 m.setCaption( 'MenuExample' )
 m.show()
 a.connect( a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()') )
 a.exec_loop()






More information about the PyQt mailing list