当前位置: 首页>>代码示例>>Python>>正文


Python QTableWidget.setFixedWidth方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QTableWidget.setFixedWidth方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidget.setFixedWidth方法的具体用法?Python QTableWidget.setFixedWidth怎么用?Python QTableWidget.setFixedWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QTableWidget的用法示例。


在下文中一共展示了QTableWidget.setFixedWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GEdges

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setFixedWidth [as 别名]
class GEdges(QGraphicsLineItem):
    def __init__(self, x1, y1, x2, y2):
        QGraphicsEllipseItem.__init__(self, x1, y1, x2, y2)
        self.point_to = 0
        self.point_from = 0
        self.path_point = 0
        self.path_point_to = 0
        self.tbl = QTableWidget(1, 2)
        item = QTableWidgetItem("0:00")
        self.tbl.setItem(0, 0, item)
        item = QTableWidgetItem("0:00")
        self.tbl.setItem(0, 1, item)
        self.tbl.setFixedWidth(219)
        item = QTableWidgetItem("time of origin")
        self.tbl.setHorizontalHeaderItem(0, item)
        item = QTableWidgetItem("path time")
        self.tbl.setHorizontalHeaderItem(1, item)

    def save_points(self):
        self.point_from.out_edges.append(self)
        self.point_to.in_edges.append(self)

    def mouseDoubleClickEvent(self, event):
        if event.button() == Qt.LeftButton:
            print("RDACT!")

    def set_point_to(self, point):
        self.point_to = point

    def set_point_from(self, point):
        self.point_from = point

    def weight(self, time):
        for i in range(0, self.tbl.rowCount()):
            if datetime.datetime.strptime(self.tbl.item(i, 0).text(), "%H:%M") > time:
                return datetime.datetime.strptime(self.tbl.item(i, 1).text(), "%H:%M")+datetime.timedelta(hours=datetime.datetime.strptime(self.tbl.item(i, 0).text(), "%H:%M").hour, minutes=datetime.datetime.strptime(self.tbl.item(i, 0).text(), "%H:%M").minute)-datetime.timedelta(hours=time.hour, minutes=time.minute)
        return datetime.datetime.strptime("14:28", "%H:%M")

    def save_info(self, tbl):
        self.tbl = tbl
开发者ID:makaronnik13,项目名称:pathfinder,代码行数:42,代码来源:GEdges.py

示例2: TournamentOrganizerWidget

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setFixedWidth [as 别名]
class TournamentOrganizerWidget(QWidget):
	def __init__(self, parent):
		super(TournamentOrganizerWidget, self).__init__(parent)
		self.parent = parent

		# Default Players (for quick testing)
		player_names = [
			'Frodo',
			'Sam',
			'Merry',
			'Pippin',
			'Gandalf',
			'Aragorn',
			'Legolas',
			'Gimli',
			'Boromir'
		]
		# for name in player_names:
		# 	to.add_player(name, None)

		self.sort_order = 'by_name'

		view.notifier.observers.append(self)

		self.header_label = QLabel('Players')

		self.header_widget = QWidget(self)
		header_layout = QBoxLayout(QBoxLayout.LeftToRight)
		header_layout.addWidget(self.header_label)
		self.header_widget.setLayout(header_layout)

		self.sort_by_name_btn = QPushButton('Sort by Name', self)
		self.sort_by_name_btn.clicked.connect(self.sort_by_name)
		self.sort_by_rank_btn = QPushButton('Sort by Rank', self)
		self.sort_by_rank_btn.clicked.connect(self.sort_by_rank)

		self.sort_btns_widget = QWidget(self)
		sort_btns_layout = QBoxLayout(QBoxLayout.LeftToRight)
		sort_btns_layout.addWidget(self.sort_by_name_btn)
		sort_btns_layout.addSpacing(10)
		sort_btns_layout.addWidget(self.sort_by_rank_btn)
		self.sort_btns_widget.setLayout(sort_btns_layout)

		self.player_list = QTableWidget(style.style_loader.TABLE_INITIAL_LENGTH, 2, self)
		self.player_list.setHorizontalHeaderLabels(['Name', 'Record'])
		self.player_list.setFixedHeight(300)
		self.player_list.setFixedWidth(400)
		self.player_list.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
		self.player_list.verticalHeader().setSectionResizeMode(QHeaderView.Fixed)
		self.player_list.horizontalHeader().setVisible(True)

		self.player_list_widget = QWidget(self)
		player_list_layout = QBoxLayout(QBoxLayout.LeftToRight)
		player_list_layout.addWidget(self.player_list)
		self.player_list_widget.setLayout(player_list_layout)

		self.add_player_btn = QPushButton('Add Player', self)
		self.add_player_btn.clicked.connect(self.parent.show_add_player_widget)
		self.remove_player_btn = QPushButton('Remove Player', self)
		self.remove_player_btn.clicked.connect(self.parent.show_remove_player_widget)

		self.player_btns_widget = QWidget(self)
		player_btn_layout = QBoxLayout(QBoxLayout.LeftToRight)
		player_btn_layout.addWidget(self.add_player_btn)
		player_btn_layout.addSpacing(10)
		player_btn_layout.addWidget(self.remove_player_btn)
		self.player_btns_widget.setLayout(player_btn_layout)

		self.error = None

		layout = QFormLayout()
		layout.addRow(self.header_widget)
		layout.addRow(self.sort_btns_widget)
		layout.addRow(self.player_list_widget)
		layout.addRow(self.player_btns_widget)
		self.setLayout(layout)

		self.update()

	def update(self):
		self.player_list.clearContents()

		players = [to.players[player] for player in to.sorted_players(self.sort_order)]

		index = 0
		for player in players:
			if index == self.player_list.rowCount():
				self.player_list.insertRow(index)
			name_item = QTableWidgetItem(player.name)
			name_item.setFlags(name_item.flags() & ~Qt.ItemIsEditable)
			self.player_list.setItem(index, 0, name_item)
			record_item = QTableWidgetItem(player.record_str())
			record_item.setFlags(record_item.flags() & ~Qt.ItemIsEditable)
			self.player_list.setItem(index, 1, record_item)
			index += 1
		self.player_list.show()

	def sort_by_name(self):
		self.sort_order = 'by_name'
		self.update()
#.........这里部分代码省略.........
开发者ID:zlohner,项目名称:TournamentOrganizer,代码行数:103,代码来源:tournament_organizer_widget.py

示例3: PairingsWidget

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setFixedWidth [as 别名]
class PairingsWidget(QWidget):
	def __init__(self, parent):
		super(PairingsWidget, self).__init__(parent)
		self.parent = parent

		view.notifier.observers.append(self)

		self.header_label = QLabel('Pairings')

		self.header_widget = QWidget(self)
		header_layout = QBoxLayout(QBoxLayout.TopToBottom)
		header_layout.addWidget(self.header_label)
		self.header_widget.setLayout(header_layout)

		self.pairings_list = QTableWidget(style.style_loader.TABLE_INITIAL_LENGTH, 2, self)
		self.pairings_list.setFixedHeight(300)
		self.pairings_list.setFixedWidth(400)
		self.pairings_list.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
		self.pairings_list.verticalHeader().setSectionResizeMode(QHeaderView.Fixed)

		self.pairings_list_widget = QWidget(self)
		pairings_list_layout = QBoxLayout(QBoxLayout.LeftToRight)
		pairings_list_layout.addWidget(self.pairings_list)
		self.pairings_list_widget.setLayout(pairings_list_layout)

		self.report_btn = QPushButton('Report Results', self)
		self.report_btn.clicked.connect(parent.show_report_result_widget)

		self.report_btn_widget = QWidget(self)
		report_btn_layout = QBoxLayout(QBoxLayout.LeftToRight)
		report_btn_layout.addWidget(self.report_btn)
		self.report_btn_widget.setLayout(report_btn_layout)

		layout = QFormLayout()
		layout.addRow(self.header_widget)
		layout.addRow(self.pairings_list_widget)
		layout.addRow(self.report_btn_widget)
		self.setLayout(layout)

		self.update()

	def update(self):
		self.pairings_list.clearContents()

		index = 0
		for p1, p2 in to.pairings.items():
			if index == self.pairings_list.rowCount():
				self.pairings_list.insertRow(index)
			p1_item = QTableWidgetItem(p1)
			p1_item.setFlags(p1_item.flags() & ~Qt.ItemIsEditable)
			self.pairings_list.setItem(index, 0, p1_item)
			if p2 == None:
				p2_str = '--BYE--'
			else:
				p2_str = p2
			p2_item = QTableWidgetItem(p2_str)
			p2_item.setFlags(p2_item.flags() & ~Qt.ItemIsEditable)
			self.pairings_list.setItem(index, 1, p2_item)
			index += 1
		self.pairings_list.show()

	def player_added(self, player, user):
		pass

	def player_removed(self, player):
		pass

	def pairings_created(self):
		self.update()
		self.parent.show()

	def report_result(self, player, record, win_loss_draw):
		try:
			if win_loss_draw == 'win':
				to.record_win(player, record)
			elif win_loss_draw == 'loss':
				to.record_loss(player, record)
			elif win_loss_draw == 'draw':
				to.record_draw(player, record)
			view.notifier.result_reported()
		except TournamentException as ex:
			self.error = ErrorMessage(str(ex), '')
			self.error.setStyleSheet(style.style_loader.stylesheet)
			self.error.show()

	def result_reported(self):
		self.update()
		self.parent.show()

	def reset(self):
		self.update()
		self.parent.show()
开发者ID:zlohner,项目名称:TournamentOrganizer,代码行数:94,代码来源:pairings_widget.py

示例4: UserManagerWidget

# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import setFixedWidth [as 别名]
class UserManagerWidget(QWidget):
	def __init__(self, parent):
		super(UserManagerWidget, self).__init__(parent)
		self.parent = parent

		self.sort_order = 'by_name'

		view.notifier.observers.append(self)

		self.header_label = QLabel('Users')

		self.header_widget = QWidget(self)
		header_layout = QBoxLayout(QBoxLayout.LeftToRight)
		header_layout.addWidget(self.header_label)
		self.header_widget.setLayout(header_layout)

		self.sort_by_name_btn = QPushButton('Sort by Name', self)
		self.sort_by_name_btn.clicked.connect(self.sort_by_name)
		self.sort_by_rank_btn = QPushButton('Sort by Rank', self)
		self.sort_by_rank_btn.clicked.connect(self.sort_by_rank)

		self.sort_btns_widget = QWidget(self)
		sort_btns_layout = QBoxLayout(QBoxLayout.LeftToRight)
		sort_btns_layout.addWidget(self.sort_by_name_btn)
		sort_btns_layout.addSpacing(10)
		sort_btns_layout.addWidget(self.sort_by_rank_btn)
		self.sort_btns_widget.setLayout(sort_btns_layout)

		self.user_list = QTableWidget(style.style_loader.TABLE_INITIAL_LENGTH, 3, self)
		self.user_list.setFixedHeight(300)
		self.user_list.setFixedWidth(400)
		self.user_list.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
		self.user_list.verticalHeader().setSectionResizeMode(QHeaderView.Fixed)

		self.user_list_widget = QWidget(self)
		user_list_layout = QBoxLayout(QBoxLayout.LeftToRight)
		user_list_layout.addWidget(self.user_list)
		self.user_list_widget.setLayout(user_list_layout)

		self.add_player_btn = QPushButton('Add User', self)
		self.add_player_btn.clicked.connect(self.parent.show_add_user_widget)
		self.remove_player_btn = QPushButton('Remove User', self)
		self.remove_player_btn.clicked.connect(self.parent.show_remove_user_widget)

		self.player_btns_widget = QWidget(self)
		player_btn_layout = QBoxLayout(QBoxLayout.LeftToRight)
		player_btn_layout.addWidget(self.add_player_btn)
		player_btn_layout.addSpacing(10)
		player_btn_layout.addWidget(self.remove_player_btn)
		self.player_btns_widget.setLayout(player_btn_layout)

		self.error = None

		layout = QFormLayout()
		layout.addRow(self.header_widget)
		layout.addRow(self.sort_btns_widget)
		layout.addRow(self.user_list_widget)
		layout.addRow(self.player_btns_widget)
		self.setLayout(layout)

		self.update()

	def update(self):
		self.user_list.clearContents()
		# TODO: get the most recent user list
		users = um.users()

		index = 0
		for user in users:
			if index == self.user_list.rowCount():
				self.user_list.insertRow(index)
			name_item = QTableWidgetItem(user.name)
			name_item.setFlags(name_item.flags() & ~Qt.ItemIsEditable)
			self.user_list.setItem(index, 0, name_item)
			id_item = QTableWidgetItem(str(user.id))
			id_item.setFlags(id_item.flags() & ~Qt.ItemIsEditable)
			self.user_list.setItem(index, 1, id_item)
			record_item = QTableWidgetItem(user.record_str())
			record_item.setFlags(record_item.flags() & ~Qt.ItemIsEditable)
			self.user_list.setItem(index, 2, record_item)
			index += 1
		self.user_list.show()

	def sort_by_name(self):
		self.sort_order = 'by_name'
		self.update()

	def sort_by_rank(self):
		self.sort_order = 'by_rank'
		self.update()

	def player_added(self, player, user):
		self.update()

	def player_removed(self, player):
		self.update()

	def report_result(self, player, record, win_or_draw):
		pass

#.........这里部分代码省略.........
开发者ID:zlohner,项目名称:TournamentOrganizer,代码行数:103,代码来源:user_manager_widget.py


注:本文中的PyQt5.QtWidgets.QTableWidget.setFixedWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。