本文整理匯總了Python中spyderlib.qt.QtGui.QListWidget.setMinimumWidth方法的典型用法代碼示例。如果您正苦於以下問題:Python QListWidget.setMinimumWidth方法的具體用法?Python QListWidget.setMinimumWidth怎麽用?Python QListWidget.setMinimumWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類spyderlib.qt.QtGui.QListWidget
的用法示例。
在下文中一共展示了QListWidget.setMinimumWidth方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FileSwitcher
# 需要導入模塊: from spyderlib.qt.QtGui import QListWidget [as 別名]
# 或者: from spyderlib.qt.QtGui.QListWidget import setMinimumWidth [as 別名]
#.........這裏部分代碼省略.........
if self.initial_editor in self.paths_by_editor:
index = self.paths.index(self.initial_path)
self.sig_goto_file.emit(index)
def set_dialog_position(self):
"""Positions the file switcher dialog in the center of the editor."""
parent = self.parent()
geo = parent.geometry()
width = self.list.width() # This has been set in setup
left = parent.geometry().width()/2 - width/2
top = 0
while parent:
geo = parent.geometry()
top += geo.top()
left += geo.left()
parent = parent.parent()
# Note: the +1 pixel on the top makes it look better
self.move(left, top + self.tabs.tabBar().geometry().height() + 1)
def fix_size(self, content, extra=50):
"""Adjusts the width of the file switcher, based on the content."""
# Update size of dialog based on longest shortened path
strings = []
if content:
for rich_text in content:
label = QLabel(rich_text)
label.setTextFormat(Qt.PlainText)
strings.append(label.text())
fm = label.fontMetrics()
max_width = max([fm.width(s)*1.3 for s in strings])
self.list.setMinimumWidth(max_width + extra)
self.set_dialog_position()
# --- Helper methods: List widget
def count(self):
"""Gets the item count in the list widget."""
return self.list.count()
def current_row(self):
"""Returns the current selected row in the list widget."""
return self.list.currentRow()
def set_current_row(self, row):
"""Sets the current selected row in the list widget."""
return self.list.setCurrentRow(row)
def select_row(self, steps):
"""Select row in list widget based on a number of steps with direction.
Steps can be positive (next rows) or negative (previous rows).
"""
row = self.current_row() + steps
if 0 <= row < self.count():
self.set_current_row(row)
def previous_row(self):
"""Select previous row in list widget."""
self.select_row(-1)
def next_row(self):
"""Select next row in list widget."""
self.select_row(+1)