add menu, toolbar. modify QWidget to QMainWindow

master3.3
Спиридонов Денис 13 years ago
parent 7be47240fc
commit 78bac1e35c

114
Box.py

@ -1,83 +1,42 @@
#!/usr/bin/python
#-*- coding: utf-8 -*-
from PySide import QtGui, QtCore
from PySide.QtGui import QScrollArea, QLabel
from leftmenu import LeftMenu
from PySide.QtGui import QScrollArea, QLabel, QMessageBox
class Check(QtGui.QWidget):
def __init__(self):
super(Check, self).__init__()
self.initUI()
def initUI(self):
self.lbl = QtGui.QLabel("Ubuntu", self)
combo = QtGui.QComboBox(self)
combo.addItem("Ubuntu")
combo.addItem("Mandriva")
combo.addItem("Fedora")
combo.addItem("Red Hat")
combo.addItem("Gentoo")
combo.move(50, 50)
self.lbl.move(50, 150)
from leftmenu import LeftMenu
from statusfield import StatusField
from mainframe import MainFrame
from mainmenu import MainMenu
combo.activated[str].connect(self.onActivated)
self.setGeometry(0, 0, 150, 180)
self.setWindowTitle('QtGui.QComboBox')
self.show()
def onActivated(self, text):
if text == 'Gentoo':
if hasattr (self, 'lbl'): #if 'lbl' in self:
self.lbl.hide()
del self.lbl
else:
if not hasattr (self, 'lbl'):
self.lbl = QtGui.QLabel(text, self)
self.lbl.move(50, 150)
self.lbl.show()
self.lbl.setText(text)
self.lbl.adjustSize()
class Example(QtGui.QWidget):
#class Example(QtGui.QWidget):
class Example(QtGui.QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
def initUI(self):
# Создание нижнего статус бара
self.statusbar = self.statusBar()
self.statusbar.showMessage('Ready')
hbox = QtGui.QHBoxLayout(self)
# Создание верхнего главного меню
MainMenu(self)
# левое верхнее меню
topleft = LeftMenu(self)
# верхнее правое
check2 = Check()
self.scrollArea2 = QtGui.QScrollArea()
self.scrollArea2.setWidget(check2)
self.main_frame = MainFrame(self)
# создание нижнего фрейма
bottom = QtGui.QFrame(self)
# bottom.setFrameShape(QLabel.Panel)
tempbox3 = QtGui.QHBoxLayout(self)
check3 = Check()
self.scrollArea3 = QtGui.QScrollArea()
self.scrollArea3.horizontalScrollBar().hide()
self.scrollArea3.setWidget(check3)
tempbox3.addWidget(self.scrollArea3)
bottom.setLayout(tempbox3)
bottom = StatusField(self)
# объединение в один виджет
splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(self.scrollArea2)
splitter1.addWidget(self.main_frame)
splitter1.setGeometry(0, 0, 0, 140)
splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)
@ -86,9 +45,11 @@ class Example(QtGui.QWidget):
hbox.addWidget(splitter2)
self.setLayout(hbox)
# self.setLayout(hbox)
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
CentralWidget = QtGui.QWidget()
CentralWidget.setLayout(hbox)
self.setCentralWidget(CentralWidget)
self.setGeometry(200, 200, 800, 800)
self.setWindowTitle('QtGui.QSplitter')
@ -97,11 +58,24 @@ class Example(QtGui.QWidget):
self.lbl.setText(text)
self.lbl.adjustSize()
#def closeEvent(self, event):
#reply = QtGui.QMessageBox.question(self, 'Message',
#"Are you sure to quit?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
#if reply == QtGui.QMessageBox.Yes:
#event.accept()
#else:
#event.ignore()
# def closeEvent(self, event):
## reply = QtGui.QMessageBox.question(self, 'Message',
## "Close your session?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No,\
## QtGui.QMessageBox.Cancel)
#
# msgBox = QMessageBox()
# msgBox.setText("Close your session?")
# msgBox.setInformativeText('at closing session, '
# 'data all processes will be deleted!')
# msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No | \
# QMessageBox.Cancel)
# msgBox.setDefaultButton(QMessageBox.Save)
# reply = msgBox.exec_()
#
# if reply == QtGui.QMessageBox.Yes:
# '''Closing session...'''
# event.accept()
# elif reply == QtGui.QMessageBox.No:
# event.accept()
# else:
# event.ignore()

@ -7,10 +7,10 @@ from Box import Example
app = QtGui.QApplication(sys.argv)
#qb = MessageBox()
#qb.show()
ex = Example()
f = QtGui.QStyleFactory().create('Motif')
#ex.setStyle(f)
#ex.setStyle('Windows')
ex.show()
sys.exit(app.exec_())

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@ -46,15 +46,15 @@ class LeftMenu(QtGui.QFrame):
def __init__(self, parent):
QtGui.QFrame.__init__(self)
# верхнее левое меню
topleft = QtGui.QFrame(self)
topleft.setFrameShape(QtGui.QFrame.NoFrame)
topleft.setGeometry(0, 0, 100, 20)
# topleft = QtGui.QFrame(self)
# self.setFrameShape(QtGui.QFrame.NoFrame)
self.setGeometry(0, 0, 100, 20)
check1 = Checkbox()
tempbox = QtGui.QHBoxLayout(self)
self.scrollArea1 = QtGui.QScrollArea()
self.scrollArea1.setWidget(check1)
tempbox = QtGui.QHBoxLayout(self)
tempbox.addWidget(self.scrollArea1)
topleft.setLayout(tempbox)
self.setLayout(tempbox)

@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
from PySide import QtGui
class Check(QtGui.QWidget):
def __init__(self):
super(Check, self).__init__()
self.initUI()
def initUI(self):
self.lbl = QtGui.QLabel("Ubuntu", self)
combo = QtGui.QComboBox(self)
combo.addItem("Ubuntu")
combo.addItem("Mandriva")
combo.addItem("Fedora")
combo.addItem("Red Hat")
combo.addItem("Gentoo")
combo.move(50, 50)
self.lbl.move(50, 150)
combo.activated[str].connect(self.onActivated)
self.setGeometry(0, 0, 150, 180)
self.setWindowTitle('QtGui.QComboBox')
self.show()
def onActivated(self, text):
if text == 'Gentoo':
if hasattr (self, 'lbl'): #if 'lbl' in self:
self.lbl.hide()
del self.lbl
else:
if not hasattr (self, 'lbl'):
self.lbl = QtGui.QLabel(text, self)
self.lbl.move(50, 150)
self.lbl.show()
self.lbl.setText(text)
self.lbl.adjustSize()
class MainFrame (QtGui.QScrollArea):
def __init__(self, parent):
QtGui.QScrollArea.__init__(self)
# верхнее правое
check2 = Check()
self.setWidget(check2)

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from PySide import QtGui
class MainMenu():
def __init__(self, parent):
exitAction = QtGui.QAction(QtGui.QIcon('image/Exit.png'), '&Exit', parent)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(parent.close)
parent.toolbar = parent.addToolBar('Exit')
parent.toolbar.addAction(exitAction)
# menubar = parent.menuBar()
# fileMenu = menubar.addMenu('&File')
# fileMenu.addAction(exitAction)

@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
from PySide import QtGui
class Checkbox(QtGui.QWidget):
def __init__(self):
super(Checkbox, self).__init__()
self.initUI()
def initUI(self):
self.lbl = QtGui.QLabel("Town", self)
self.combo = QtGui.QComboBox(self)
self.combo.addItem("Town")
self.combo.addItem("City")
self.combo.addItem("Village")
self.combo.move(50, 50)
self.lbl.move(150, 50)
self.combo.activated[str].connect(self.onActivated)
self.setGeometry(50, 50, 200, 100)
self.setWindowTitle('QtGui.QComboBox')
self.show()
def onActivated(self, text):
if text == 'Village':
if hasattr (self, 'lbl'): #if 'lbl' in self:
self.lbl.hide()
del self.lbl
else:
if not hasattr (self, 'lbl'):
self.lbl = QtGui.QLabel(text, self)
self.lbl.move(150, 50)
self.lbl.show()
self.lbl.setText(text)
self.lbl.adjustSize()
class StatusField (QtGui.QFrame):
def __init__(self, parent):
# создание нижнего фрейма
# bottom = QtGui.QFrame(self)
QtGui.QFrame.__init__(self)
tempbox3 = QtGui.QHBoxLayout(self)
check3 = Checkbox()
self.scrollArea3 = QtGui.QScrollArea()
self.scrollArea3.horizontalScrollBar().hide()
self.scrollArea3.setWidget(check3)
tempbox3.addWidget(self.scrollArea3)
self.setLayout(tempbox3)
check3.combo.activated[str].connect(parent.statusbar.showMessage)
Loading…
Cancel
Save