Esempio n. 1
0
 def editorEvent(self, event, model, option, index):
     """edit right aligned checkbox"""
     flags = model.flags(index)
     # make sure that the item is checkable
     if (not (flags & Qt.ItemIsUserCheckable)
             or not (flags & Qt.ItemIsEnabled)):
         return False
     # make sure that we have a check state
     value = index.data(Qt.CheckStateRole)
     if not value.isValid():
         return False
     # make sure that we have the right event type
     if event.type() == QEvent.MouseButtonRelease:
         textMargin = self.__textMargin()
         checkRect = QStyle.alignedRect(
             option.direction, Qt.AlignRight, option.decorationSize,
             QRect(option.rect.x() + (2 * textMargin), option.rect.y(),
                   option.rect.width() - (2 * textMargin),
                   option.rect.height()))
         if not checkRect.contains(event.pos()):
             return False
     elif event.type() == QEvent.KeyPress:
         if event.key() not in (Qt.Key_Space, Qt.Key_Select):
             return False
     else:
         return False
     if value.toInt()[0] == Qt.Checked:
         state = Qt.Unchecked
     else:
         state = Qt.Checked
     return model.setData(index, state, Qt.CheckStateRole)
Esempio n. 2
0
 def paint(self, painter, option, index):
     """paint right aligned checkbox"""
     viewItemOption = QStyleOptionViewItemV4(option)
     if self.cellFilter(index):
         textMargin = self.__textMargin()
         newRect = QStyle.alignedRect(
             option.direction, Qt.AlignRight,
             QSize(option.decorationSize.width() + 5,
                   option.decorationSize.height()),
             QRect(option.rect.x() + textMargin, option.rect.y(),
                   option.rect.width() - (2 * textMargin),
                   option.rect.height()))
         viewItemOption.rect = newRect
     QStyledItemDelegate.paint(self, painter, viewItemOption, index)
Esempio n. 3
0
    def start(self):
        """
        Starts the main window
        """
        QTApp = QtGui.QApplication(sys.argv)

        app_dir = os.path.dirname(os.path.realpath(__file__))
        icon_dir = app_dir + os.path.sep + "icons" + os.path.sep

        mainWindow = UiMainWindow(self.VERSION, icon_path=icon_dir)
        mainWindow.setGeometry(
            QStyle.alignedRect(
                QtCore.Qt.LeftToRight,
                QtCore.Qt.AlignCenter,
                mainWindow.size(),
                QTApp.desktop().availableGeometry()))

        mainWindow.show()

        sys.exit(QTApp.exec_())
Esempio n. 4
0
def center_widget_on_desktop(widget):
    widget.setGeometry(QStyle.alignedRect(Qt.LeftToRight,
                                          Qt.AlignCenter,
                                          widget.size(),
                                          qApp.desktop().availableGeometry()))