Найти - Пользователи
Полная версия: PyQT4 помощь с дизайном. Помогите плиз...
Начало » GUI » PyQT4 помощь с дизайном. Помогите плиз...
1 2
villager
копался как-то - пытался сделать окно как в Nokia Ovi
нашел такой пример (перевод с Си)
здесь системный titlebar убирается, а вставляется свой
и на нем можно разместить меню и что угодно
может подойдет
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.Qt import *
import sys

class TitleBar(QDialog):
def __init__(self, pw):
# // Don't let this widget inherit the parent's backround color
QWidget.__init__(self)
self.setAutoFillBackground(True)
# // Use a brush with a Highlight color role to render the background
self.setBackgroundRole(QPalette.Highlight)

self.minimize = QToolButton(self)
self.maximize = QToolButton(self)
self.close= QToolButton(self)

pix = self.style().standardPixmap(QStyle.SP_TitleBarCloseButton)
self.close.setIcon(QIcon(pix))

self.maxPix = self.style().standardPixmap(QStyle.SP_TitleBarMaxButton)
self.maximize.setIcon(QIcon(self.maxPix))

pix = self.style().standardPixmap(QStyle.SP_TitleBarMinButton)
self.minimize.setIcon(QIcon(pix))

self.restorePix = self.style().standardPixmap(QStyle.SP_TitleBarNormalButton)

# self.minimize.setMinimumHeight(15)
# self.close.setMinimumHeight(15)
# self.maximize.setMinimumHeight(15)

self.minimize.setMaximumHeight(15)
self.close.setMaximumHeight(15)
self.maximize.setMaximumHeight(15)


label = QLabel()
label.setText("Window*Title")
pw.setWindowTitle(label.text())
pw.setWindowIcon(QIcon(self.restorePix))

hbox = QHBoxLayout(self)
hbox.setMargin(0)
hbox.addWidget(label)
hbox.insertStretch(1, 500)

hbox.addWidget(self.minimize)
hbox.addWidget(self.maximize)
hbox.addWidget(self.close)

hbox.setSpacing(0)
# self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
# self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

self.maxNormal = False

self.close.clicked.connect(pw.close)
self.minimize.clicked.connect(self.showSmall)
self.maximize.clicked.connect(self.showMaxRestore)

def showSmall(self):
self.parentWidget().showMinimized()
def showMaxRestore(self):
if self.maxNormal:
self.parentWidget().showNormal()
self.maxNormal = not self.maxNormal
self.maximize.setIcon(QIcon(self.maxPix))
else:
self.parentWidget().showMaximized()
self.maxNormal = not self.maxNormal
self.maximize.setIcon(QIcon(self.restorePix))
def mousePressEvent(self, me):
self.startPos = me.globalPos();
self.clickPos = self.mapToParent(me.pos())
def mouseMoveEvent(self, me):
if self.maxNormal: return
self.parentWidget().move(me.globalPos() - self.clickPos)

class Frame(QFrame):
def __init__(self):
self.m_mouse_down = False
QFrame.__init__(self)
self.setFrameShape(1)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setMouseTracking(True);

self.m_titleBar =TitleBar(self)

self.m_content = QWidget(self)

vbox = QVBoxLayout(self)
vbox.addWidget(self.m_titleBar)
vbox.setMargin(0)
vbox.setSpacing(0)

layout = QVBoxLayout(self)
layout.addWidget(self.m_content)
layout.setMargin(2);
layout.setSpacing(0);
vbox.addLayout(layout)
def contentWidget(self): return self.m_content
def titleBar(): return self.m_titleBar
def mousePressEvent(self, e):
self.m_old_pos = e.pos()
self.m_mouse_down = e.button() == Qt.LeftButton
def mouseMoveEvent(self, e):
x = e.x()
y = e.y()
if (self.m_mouse_down):
dx = x - self.m_old_pos.x();
dy = y - self.m_old_pos.y();
g = self.geometry();
if self.left:
g.setLeft(g.left() + dx)
if self.right:
g.setRight(g.right() + dx)
if self.bottom:
g.setBottom(g.bottom() + dy)
self.setGeometry(g)
self.m_old_pos = QPoint(e.x() if not self.left else self.m_old_pos.x(), e.y())
else:
r = self.rect()
self.left = abs(x - r.left()) <= 5
self.right = abs(x - r.right()) <= 5;
self.bottom = abs(y - r.bottom()) <= 5;
hor = self.left | self.right

if (hor and self.bottom):
if self.left:
self.setCursor(Qt.SizeBDiagCursor)
else:
self.setCursor(Qt.SizeFDiagCursor)
elif hor:
self.setCursor(Qt.SizeHorCursor)
elif self.bottom:
self.setCursor(Qt.SizeVerCursor)
else:
self.setCursor(Qt.ArrowCursor)
def mouseReleaseEvent(self, e):
self.m_mouse_down = False


if __name__ == "__main__":
app = QApplication(sys.argv)
box=Frame ()
box.move(110,110);

l=QVBoxLayout(box.contentWidget())
l.setMargin(0)
tbl = QTableWidget( 5, 5)

tbl.dragEnabled()
tbl.setDragDropMode(QAbstractItemView.DragDrop)
tbl.setDropIndicatorShown(True)
def myDropEvent(event):
event.acceptProposedAction()
print tbl.itemAt(event.pos())
tbl.dropEvent=myDropEvent
def myDragMoveEvent(event):
print tbl.itemAt(event.pos())
# event.acceptProposedAction()
pass
def myMouseMoveEvent(e):
print "mouse move", e.pos(), tbl.itemAt(e.pos())
tbl.mouseMoveEvent=myMouseMoveEvent
tbl.dragMoveEvent=myDragMoveEvent

l.addWidget(tbl)

box.show()
app.exec_()
Nyappa
villager
спасибо =) ты очень мне помог =))))))
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB