from PyQt4.QtCore import *
from PyQt4.QtGui import *
SCREEN_BORDER = 100
def __init__(self, parent=None):
super(GraphicsView, self).__init__(parent)
class MouseCoordinates
(QLabel):
def __init__(self, parent=None):
super(MouseCoordinates, self).__init__(parent)
self.update()
def update(self):
x = currentPos.x()
y = currentPos.y()
self.setText(" Mouse: %d / %d " % (x, y))
def __init__(self, parent=None):
super(StatusBar, self).__init__(parent)
self.mouseCoords = MouseCoordinates()
self.addWidget(self.mouseCoords)
self.update()
def update(self):
self.mouseCoords.update()
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.
scene.
setSceneRect(QRectF(0,
0,
800,
600))
# draw border
self.
scene.
addRect(QRectF(0,
0,
800,
600),
QPen(Qt.
darkGray,
1, Qt.
DotLine),
# save the current rect as parent object (canvas) for drawing
self.canvas = self.scene.items()[0]
# add view
self.view = GraphicsView()
self.view.setScene(self.scene)
self.status = StatusBar()
if self.status.isSizeGripEnabled():
self.status.setSizeGripEnabled(False)
self.setStatusBar(self.status)
self.setCentralWidget(self.view)
def mouseMoveEvent(self, event):
self.status.update()
super(MainWindow, self).mouseMoveEvent(event)
if __name__ == "__main__":
import sys
# setup application object
# create (parent) main window
mainWindow = MainWindow()
mainWindow.setGeometry(rect.x() + SCREEN_BORDER,
rect.y() + SCREEN_BORDER,
rect.width() - 2 * SCREEN_BORDER,
rect.height() - 2 * SCREEN_BORDER)
mainWindow.setMinimumSize(900, 700)
mainWindow.
setWindowIcon(QIcon("Icon.bmp")) mainWindow.setWindowTitle("DesignerTest")
mainWindow.show()
# run application object
sys.exit(app.exec_())
from PyQt4.QtCore import *
from PyQt4.QtGui import *
SCREEN_BORDER = 100
class GraphicsView(QGraphicsView):
def __init__(self, parent=None):
super(GraphicsView, self).__init__(parent)
class MouseCoordinates(QLabel):
def __init__(self, parent=None):
super(MouseCoordinates, self).__init__(parent)
self.update()
def update(self):
currentPos = QCursor.pos()
x = currentPos.x()
y = currentPos.y()
self.setText(" Mouse: %d / %d " % (x, y))
class StatusBar(QStatusBar):
def __init__(self, parent=None):
super(StatusBar, self).__init__(parent)
self.mouseCoords = MouseCoordinates()
self.addWidget(self.mouseCoords)
self.update()
def update(self):
self.mouseCoords.update()
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.scene = QGraphicsScene(self)
self.scene.setSceneRect(QRectF(0, 0, 800, 600))
# draw border
self.scene.addRect(QRectF(0, 0, 800, 600),
QPen(Qt.darkGray, 1, Qt.DotLine),
QBrush(Qt.lightGray))
# save the current rect as parent object (canvas) for drawing
self.canvas = self.scene.items()[0]
# add view
self.view = GraphicsView()
self.view.setScene(self.scene)
self.status = StatusBar()
if self.status.isSizeGripEnabled():
self.status.setSizeGripEnabled(False)
self.setStatusBar(self.status)
self.setCentralWidget(self.view)
def mouseMoveEvent(self, event):
self.status.update()
super(MainWindow, self).mouseMoveEvent(event)
if __name__ == "__main__":
import sys
# setup application object
app = QApplication(sys.argv)
# create (parent) main window
mainWindow = MainWindow()
rect = QApplication.desktop().availableGeometry()
mainWindow.setGeometry(rect.x() + SCREEN_BORDER,
rect.y() + SCREEN_BORDER,
rect.width() - 2 * SCREEN_BORDER,
rect.height() - 2 * SCREEN_BORDER)
mainWindow.setMinimumSize(900, 700)
mainWindow.setWindowIcon(QIcon("Icon.bmp"))
mainWindow.setWindowTitle("DesignerTest")
mainWindow.show()
# run application object
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks