def uiDefinitions(): # REMOVE TITLE BAR self.setWindowFlag(QtCore.Qt.FramelessWindowHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # SET DROPSHADOW WINDOW self.shadow = QGraphicsDropShadowEffect(self) self.shadow.setBlurRadius(20) self.shadow.setXOffset(0) self.shadow.setYOffset(0) self.shadow.setColor(QColor(0, 0, 0, 100)) # APPLY DROPSHADOW TO FRAME self.ui.drop_shadow_frame.setGraphicsEffect(self.shadow) # MAXIMIZE / RESTORE self.ui.maximize_btn.clicked.connect(lambda: maximize_restore()) # MINIMIZE self.ui.minimize_btn.clicked.connect(lambda: self.showMinimized()) # CLOSE self.ui.close_btn.clicked.connect(lambda: self.close()) ## ==> CREATE SIZE GRIP TO RESIZE WINDOW self.sizegrip = QSizeGrip(self.ui.frame_grip) self.sizegrip.setStyleSheet( "QSizeGrip { width: 10px; height: 10px; margin: 5px } QSizeGrip:hover { background-color: rgb(50, 42, 94) }" ) self.sizegrip.setToolTip("Resize Window")
def __init__(self, parent=None): super(DynamicNeedleMask, self).__init__(parent) self.settings = QSettings() self._first_show = True self.setWindowFlag(Qt.SubWindow) self.setFocusPolicy(Qt.ClickFocus) self.layout = QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.setCursor(Qt.SizeAllCursor) self.setGeometry(self.parent().width() / 2 - 10, 0, 20, self.parent().height()) self._old_geo = self.geometry() self._locked = False self.origin = QPoint(0, 0) self.rubberband = QRubberBand(QRubberBand.Rectangle, self) self.rubberband.move(0, 0) self.hide() self.rubberband.hide() # self.rubberband.show() # self.show() self.sideGrips = [ SideGrip(self, Qt.LeftEdge), SideGrip(self, Qt.TopEdge), SideGrip(self, Qt.RightEdge), SideGrip(self, Qt.BottomEdge), ] # corner grips should be "on top" of everything, otherwise the side grips # will take precedence on mouse events, so we are adding them *after*; # alternatively, widget.raise_() can be used self.cornerGrips = [QSizeGrip(self) for i in range(4)]
def __init__(self): super(WhatsPy, self).__init__() self.programa = Ui_Whatspy() self.programa.setupUi(self) self.programa.grip = QSizeGrip(self.programa.lblGrip) self.controlVentana = 0 self.programa.btnExportar.setEnabled(False) # Datos self.fila_numeros = None self.fila_valores = None # Mover ventana - Global def moverVentana(event): if event.buttons() == Qt.LeftButton: self.move(self.pos() + event.globalPos() - self.dragPos) self.dragPos = event.globalPos() event.accept() self.programa.Contenedor.mouseMoveEvent = moverVentana # Botones self.programa.btnVerde.clicked.connect( lambda: eventos.minimizarVentana(self)) self.programa.btnAmarillo.clicked.connect(lambda: self.estadoVentana()) self.programa.btnRojo.clicked.connect( lambda: eventos.cerrarVentana(self)) # Botones funcionales self.programa.btnAbrir.clicked.connect(lambda: self.getChat()) self.programa.btnExportar.clicked.connect( lambda: eventos.exportarChat(self.fila_numeros, self.fila_valores))
def __init__(self, log_path): super().__init__() self.setWindowFlag(Qt.X11BypassWindowManagerHint) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.size_grip = QSizeGrip(self) size_grip_height = self.size_grip.height() self.size_grip.setFixedSize(size_grip_height, size_grip_height) self.log_monitor = LogParser(log_path) self.log_monitor.trade_request.connect(self.on_trade_request) self.log_monitor.start() self.is_dragging = False self.drag_position = self.pos() self.update_title()
def __init__(self, parent=None): super(ResizableRubberBand, self).__init__(parent) self.setWindowFlag(Qt.SubWindow) self.setFocusPolicy(Qt.ClickFocus) self.layout = QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.setCursor(Qt.SizeAllCursor) self.origin = QPoint() self.grip1 = QSizeGrip(self) self.grip2 = QSizeGrip(self) self.layout.addWidget(self.grip1, 0, Qt.AlignLeft | Qt.AlignTop) self.layout.addWidget(self.grip2, 0, Qt.AlignRight | Qt.AlignBottom) self.rubberband = QRubberBand(QRubberBand.Rectangle, self) self.rubberband.move(0, 0) self.hide() self.rubberband.hide()
def paintEvent(self, event): if self.drawing : self.view.le = QPlainTextEdit() width = QtCore.QRectF(self.startPoint, self.lastPoint).size().width() height = QtCore.QRectF(self.startPoint, self.lastPoint).size().height() x = self.startPoint.x() y = self.startPoint.y() if width > 1 and height > 1: self.view.le.setGeometry(x, y, width, height) self.qsizegrip = QSizeGrip(self.view.le) self.scene.addWidget(self.view.le)
def __init__(self, parent=None): super(FrameWidget, self).__init__(parent) self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint) self.setObjectName("Master") self.setStyleSheet("#Master {background-color : transparent;}") self._gripSize = 1 self.initialGrip = self._gripSize self.sideGrips = [ SideGrip(self, Qt.LeftEdge), SideGrip(self, Qt.TopEdge), SideGrip(self, Qt.RightEdge), SideGrip(self, Qt.BottomEdge), ] self.cornerGrips = [QSizeGrip(self) for i in range(4)] self.setRatio(1280/720)
class MainWindow(QtWidgets.QMainWindow): role_value = None DATA_PATH = 'D:\\SASTRA\Code\\Dean Mam Project\\assignment\\Data\\Medical_Records.csv' def __init__(self): print('Main init') QtWidgets.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.stackedWidget.setCurrentIndex(0) for i in RBACClass.permission_dict['Administrator']: self.ui.tableWidget.setColumnHidden(i, True) ## ==> MAXIMIZE RESTORE FUNCTION def maximize_restore(): global GLOBAL_STATE status = GLOBAL_STATE # IF NOT MAXIMIZED if status == 0: self.showMaximized() # SET GLOBAL TO 1 GLOBAL_STATE = 1 # IF MAXIMIZED REMOVE MARGINS AND BORDER RADIUS self.ui.drop_shadow_frame.setContentsMargins(0, 0, 0, 0) self.ui.drop_shadow_frame.setStyleSheet( "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(42, 44, 111, 255), stop:0.521368 rgba(28, 29, 73, 255)); border-radius: 0px;" ) self.ui.maximize_btn.setToolTip("Restore") else: GLOBAL_STATE = 0 self.showNormal() self.resize(self.width() + 1, self.height() + 1) self.ui.drop_shadow_frame.setContentsMargins(10, 10, 10, 10) self.ui.drop_shadow_frame.setStyleSheet( "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(42, 44, 111, 255), stop:0.521368 rgba(28, 29, 73, 255)); border-radius: 10px;" ) self.ui.maximize_btn.setToolTip("Maximize") ## ==> UI DEFINITIONS def uiDefinitions(): # REMOVE TITLE BAR self.setWindowFlag(QtCore.Qt.FramelessWindowHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # SET DROPSHADOW WINDOW self.shadow = QGraphicsDropShadowEffect(self) self.shadow.setBlurRadius(20) self.shadow.setXOffset(0) self.shadow.setYOffset(0) self.shadow.setColor(QColor(0, 0, 0, 100)) # APPLY DROPSHADOW TO FRAME self.ui.drop_shadow_frame.setGraphicsEffect(self.shadow) # MAXIMIZE / RESTORE self.ui.maximize_btn.clicked.connect(lambda: maximize_restore()) # MINIMIZE self.ui.minimize_btn.clicked.connect(lambda: self.showMinimized()) # CLOSE self.ui.close_btn.clicked.connect(lambda: self.close()) ## ==> CREATE SIZE GRIP TO RESIZE WINDOW self.sizegrip = QSizeGrip(self.ui.frame_grip) self.sizegrip.setStyleSheet( "QSizeGrip { width: 10px; height: 10px; margin: 5px } QSizeGrip:hover { background-color: rgb(50, 42, 94) }" ) self.sizegrip.setToolTip("Resize Window") def rolePermission(role): for i in role: self.ui.tableWidget.setColumnHidden(i, False) # MOVE WINDOW def moveWindowMain(event): # RESTORE BEFORE MOVE if self.returnStatus() == 1: self.maximize_restore(self) # IF LEFT CLICK MOVE WINDOW if event.buttons() == Qt.LeftButton: self.move(self.pos() + event.globalPos() - self.dragPos) self.dragPos = event.globalPos() event.accept() def view_details(): patient_id = self.ui.patientIdLineEdit_2.text() print(patient_id) self.ui.stackedWidget.setCurrentIndex(1) with open(MainWindow.DATA_PATH, 'r') as datafile: print('inside file') readData = csv.reader(datafile) rowValue = 0 for row in readData: print('inside row') if row[1] == patient_id: self.ui.tableWidget.insertRow(rowValue) print(row[1], type(row[1])) for i in MainWindow.role_value: print('set') self.ui.tableWidget.setItem( rowValue, i, QTableWidgetItem(row[i])) rowValue = rowValue + 1 def go_back(): self.ui.stackedWidget.setCurrentIndex(0) ## ==> SET UI DEFINITIONS uiDefinitions() print(MainWindow.role_value, "rolePerm") rolePermission(MainWindow.role_value) self.ui.viewDetailsPushButton_2.clicked.connect(view_details) self.ui.back_btn.clicked.connect(go_back) # SET TITLE BAR self.ui.title_bar_2.mouseMoveEvent = moveWindowMain ## SHOW ==> MAIN WINDOW ######################################################################## self.show() ## RETURN STATUS IF WINDOWS IS MAXIMIZE OR RESTAURED def returnStatus(self): return GLOBAL_STATE ## APP EVENTS ######################################################################## def mousePressEvent(self, event): self.dragPos = event.globalPos()
class UIFunctions(MainWindow): ## ==> MAXIMIZE RESTORE FUNCTION def maximize_restore(self): global GLOBAL_STATE status = GLOBAL_STATE # IF NOT MAXIMIZED if status == 0: self.showMaximized() # SET GLOBAL TO 1 GLOBAL_STATE = 1 # IF MAXIMIZED REMOVE MARGINS AND BORDER RADIUS self.ui.drop_shadow_layout.setContentsMargins(0, 0, 0, 0) self.ui.drop_shadow_frame.setStyleSheet( "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(42, 44, 111, 255), stop:0.521368 rgba(28, 29, 73, 255)); border-radius: 0px;") self.ui.maximize_btn.setToolTip("Restore") else: GLOBAL_STATE = 0 self.showNormal() self.resize(self.width() + 1, self.height() + 1) self.ui.drop_shadow_layout.setContentsMargins(10, 10, 10, 10) self.ui.drop_shadow_frame.setStyleSheet( "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(42, 44, 111, 255), stop:0.521368 rgba(28, 29, 73, 255)); border-radius: 10px;") self.ui.maximize_btn.setToolTip("Maximize") ## ==> UI DEFINITIONS def uiDefinitions(self): # REMOVE TITLE BAR self.setWindowFlag(QtCore.Qt.FramelessWindowHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # SET DROPSHADOW WINDOW self.shadow = QGraphicsDropShadowEffect(self) self.shadow.setBlurRadius(20) self.shadow.setXOffset(0) self.shadow.setYOffset(0) self.shadow.setColor(QColor(0, 0, 0, 100)) # APPLY DROPSHADOW TO FRAME self.ui.drop_shadow_frame.setGraphicsEffect(self.shadow) # MAXIMIZE / RESTORE self.ui.maximize_btn.clicked.connect(lambda: UIFunctions.maximize_restore(self)) # MINIMIZE self.ui.minimize_btn.clicked.connect(lambda: self.showMinimized()) # CLOSE self.ui.close_btn.clicked.connect(lambda: self.close()) ## ==> CREATE SIZE GRIP TO RESIZE WINDOW self.sizegrip = QSizeGrip(self.ui.frame_grip) self.sizegrip.setStyleSheet( "QSizeGrip { width: 10px; height: 10px; margin: 5px } QSizeGrip:hover { background-color: rgb(50, 42, 94) }") self.sizegrip.setToolTip("Resize Window") ## RETURN STATUS IF WINDOWS IS MAXIMIZE OR RESTAURED def returnStatus(self): return GLOBAL_STATE
def createWidgets(self): self._tm = TableModel(self) self._tm.inputsToSkip = self.inputsToSkip self._tm.data_types_to_skip = self.data_types_to_skip self._tv = TableView(self) self.alwaysOnTop = QCheckBox("Always on top") self.alwaysOnTop.setChecked(True) self.drawInputInfoColors = QToolButton() self.drawInputInfoColors.setCheckable(True) self.drawInputInfoColors.setChecked(True) self.drawInputInfoColors.setText("Draw Color Info") self.pushButton = QPushButton() self.pushButton.setText("Refresh") self.pushButton.setFixedSize(QSize(128, 20)) self.lineEdit = QLineEdit(self) self.lineEdit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.statusBar().showMessage("System Status | Normal") self.cacheButton = QToolButton() self.cacheButton.setCheckable(True) self.cacheButton.setChecked(False) self.cacheButton.setText("use cache") v_box = QVBoxLayout() h_box = QHBoxLayout() h_box.setAlignment(Qt.AlignRight) h_box.addWidget(self.alwaysOnTop) h_box.addWidget(self.lineEdit) h_box.addWidget(self.pushButton) h_box.addWidget(self.drawInputInfoColors) h_box.addWidget(self.cacheButton) h_box.setContentsMargins(0, 0, 0, 0) v_box.addLayout(h_box) v_box.addWidget(self._tv) sizeGrip = QSizeGrip(self) # sizeGrip.setParent(self) # v_box.addWidget(sizeGrip) # v_box.setAlignment(sizeGrip, Qt.AlignBottom | Qt.AlignRight) v_box.setContentsMargins(2, 2, 2, 2) # v_box.setSpacing(0) sizeGrip.setWindowFlags(Qt.WindowStaysOnTopHint) sizeGrip.move(0, 200) central_widget = QWidget() central_widget.setLayout(v_box) self.setCentralWidget(central_widget) self.statusBar() self.proxyModel = TableSortFilterProxyModel() self.proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive) self.proxyModel.setSortCaseSensitivity(Qt.CaseInsensitive) self.proxyModel.setDynamicSortFilter(True) self.drawInputInfoColors.setChecked(True) # self.lineEdit.textChanged.connect(self._tv.updateColumns) # self.proxyModel.setSourceModel(self._tm) # self.proxyModel.filteredKeys = self._tm.attributeNameKeys self._tv.setModel(self.proxyModel) self.progressBar = QProgressBar() self.statusBar().addPermanentWidget(self.progressBar) # This is simply to show the bar # self.progressBar.setGeometry(30, 40, 200, 25) self.progressBar.setValue(0) # Connections self.alwaysOnTop.stateChanged.connect(self.changeAlwaysOnTop) self.lineEdit.textChanged.connect(self.filterRegExpChanged) self.drawInputInfoColors.clicked.connect( self.changeTableModelBackgroundRoleMethod) self.cacheButton.clicked.connect(self.changeCacheMode) self.pushButton.pressed.connect(self.reloadFusionData) self._tm.communicate.broadcast.connect(self.communication)
class MainWindow(QMainWindow): def __init__(self, log_path): super().__init__() self.setWindowFlag(Qt.X11BypassWindowManagerHint) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.size_grip = QSizeGrip(self) size_grip_height = self.size_grip.height() self.size_grip.setFixedSize(size_grip_height, size_grip_height) self.log_monitor = LogParser(log_path) self.log_monitor.trade_request.connect(self.on_trade_request) self.log_monitor.start() self.is_dragging = False self.drag_position = self.pos() self.update_title() def update_title(self): title = TITLE_FORMAT.format(self.ui.trades.count()) self.setWindowTitle(title) self.ui.title.setText(title) @QtCore.Slot(int) def on_transparency_valueChanged(self, value): self.setWindowOpacity(1 - value / 100) @QtCore.Slot() def on_close_clicked(self): self.close() @QtCore.Slot() def on_settings_clicked(self): dialog = SettingsDialog(self) dialog.show() def on_trade_request(self, data): trade_widget = TradeWidget(self, data) self.ui.trades.addTab(trade_widget, str(self.ui.trades.count() + 1)) self.update_title() @QtCore.Slot(int) def on_trades_tabCloseRequested(self, index): self.ui.trades.removeTab(index) self.update_title() def mousePressEvent(self, event): self.is_dragging = True self.drag_position = event.globalPos() def mouseMoveEvent(self, event): delta = event.globalPos() - self.drag_position self.move(self.pos() + delta) self.drag_position = event.globalPos() def mouseReleaseEvent(self, event): self.is_dragging = False def resizeEvent(self, event): position = self.size() - self.size_grip.size() self.size_grip.move(*position.toTuple())
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowFlags(Qt.FramelessWindowHint) QFontDatabase.addApplicationFont('Fonts/Roboto-Light.ttf') QFontDatabase.addApplicationFont('Fonts/Roboto-Regular.ttf') with open('QtInterface/style.qss') as stylefile: self.setStyleSheet(stylefile.read()) self.controlmenu = ElchMenuPages() self.ribbon = ElchRibbon(menus=self.controlmenu.menus) self.matplotframe = ElchPlot() self.titlebar = ElchTitlebar() self.statusbar = ElchStatusBar() panel_spacing = 20 hbox_inner = QHBoxLayout() hbox_inner.addWidget(self.matplotframe, stretch=1) hbox_inner.addWidget(self.controlmenu, stretch=0) hbox_inner.setSpacing(panel_spacing) hbox_inner.setContentsMargins(0, 0, 0, 0) vbox_inner = QVBoxLayout() vbox_inner.addWidget(self.statusbar, stretch=0) vbox_inner.addLayout(hbox_inner, stretch=1) vbox_inner.setSpacing(panel_spacing) vbox_inner.setContentsMargins(panel_spacing, panel_spacing, panel_spacing - 13, panel_spacing) sizegrip = QSizeGrip(self) hbox_mid = QHBoxLayout() hbox_mid.addLayout(vbox_inner, stretch=1) hbox_mid.addWidget(sizegrip, alignment=Qt.AlignBottom | Qt.AlignRight) hbox_mid.setContentsMargins(0, 0, 0, 0) hbox_mid.setSpacing(0) vbox_outer = QVBoxLayout() vbox_outer.addWidget(self.titlebar, stretch=0) vbox_outer.addLayout(hbox_mid, stretch=1) vbox_outer.setContentsMargins(0, 0, 0, 0) vbox_outer.setSpacing(0) hbox_outer = QHBoxLayout() hbox_outer.addWidget(self.ribbon, stretch=0) hbox_outer.addLayout(vbox_outer, stretch=1) hbox_outer.setContentsMargins(0, 0, 0, 0) hbox_outer.setSpacing(0) self.ribbon.buttongroup.buttonToggled.connect( self.controlmenu.adjust_visibility) self.ribbon.menu_buttons['Devices'].setChecked(True) self.controlmenu.menus['Plotting'].buttons['Start'].clicked.connect( self.matplotframe.start_plotting) self.controlmenu.menus['Plotting'].buttons['Clear'].clicked.connect( self.matplotframe.clear_plot) for key, button in self.controlmenu.menus['Devices'].unitbuttons.items( ): button.clicked.connect( functools.partial(self.statusbar.change_units, key)) button.clicked.connect( functools.partial(self.matplotframe.set_units, key)) self.controlmenu.menus['Plotting'].check_group.buttonToggled.connect( self.matplotframe.set_plot_visibility) self.controlmenu.menus['Devices'].unitbuttons['Temperature'].click() self.setLayout(hbox_outer) self.show()