def createListOption(self): def addItem(label, icon_pixmap, width, height): item = QListWidgetItem(list_option) item.setText(label) item.setTextAlignment(Qt.AlignHCenter) item.setIcon(QIcon(icon_pixmap)) item.setSizeHint(QSize(width, height)) list_option = QListWidget() list_option.setAutoFillBackground(True) list_option.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) list_option.setTextElideMode(Qt.ElideNone) list_option.setMovement(QListView.Static) list_option.setFlow(QListView.TopToBottom) list_option.setProperty("isWrapping", QVariant(False)) list_option.setSpacing(3) list_option.setViewMode(QListView.IconMode) items = [] items.append((QApplication.translate("option", "Connections"), "connections.png")) items.append((QApplication.translate("option", "Accounts"), "accounts.png")) items.append((QApplication.translate("option", "Aliases"), "aliases.png")) items.append((QApplication.translate("option", "Macros"), "macros.png")) items.append((QApplication.translate("option", "Keypad"), "keypad.png")) items.append((QApplication.translate("option", "Triggers"), "triggers.png")) items.append((QApplication.translate("option", "Preferences"), "preferences.png")) max_width = 0 for label, icon_name in items: w = list_option.fontMetrics().boundingRect(label).width() if w > max_width: max_width = w # An empiric method to align element in the center of the QListWidget max_width += 15 total_height = 0 for label, icon_name in items: icon_pixmap = QPixmap(":/images/" + icon_name) height = icon_pixmap.height() + list_option.fontMetrics().height() + 3 total_height += height + 5 addItem(label, icon_pixmap, max_width, height) list_option.setUniformItemSizes(True) list_option.setFixedWidth(max_width + 10) list_option.setMinimumHeight(total_height) return list_option
main_window.setAttribute(Qt.WA_TranslucentBackground) main_window.setWindowFlags(Qt.FramelessWindowHint) main_window.show() layout = QVBoxLayout(main_window) search_bar = QLineEdit() search_bar.textChanged.connect(searcher.search) search_bar.returnPressed.connect(launch_first_item) layout.addWidget(search_bar) result_list_widget = QListWidget() result_list_widget.setIconSize(QSize(*(config_options['icon size'],) * 2)) result_list_widget.setAlternatingRowColors(True) result_list_widget.setTextElideMode(Qt.ElideMiddle) result_list_widget.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel) result_list_widget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) result_list_widget.itemActivated.connect(launch_item) # Prepare alternating row colors for transparency palette = result_list_widget.palette() color = palette.brush(QPalette.Base).color() color.setAlphaF(0.9) palette.setBrush(QPalette.Base, QBrush(color)) color = palette.brush(QPalette.AlternateBase).color() color.setAlphaF(0.5) palette.setBrush(QPalette.AlternateBase, QBrush(color)) main_window.setPalette(palette) layout.addWidget(result_list_widget)