我正在编写一个论坛帖子数据库的界面。
在上面的程序中,有一个工具箱小部件包含两个小部件,主题浏览器处于活动状态。主题浏览器由具有垂直布局的父 QFrame 组成,其中包含主题论坛类别标签、导航控件小部件和小部件的主体QTableWidget
(QTW)。QTW 选择行为是QAbstractItemView.SelectRows
.
问题是,当我将函数连接到itemClicked()
信号时,信号仅在我将单元格选择到posts
andViews
列时才会触发,但在我单击主题单元格时不会触发name
。我尝试了其他信号,它们具有相同的行为。需要注意的一点是,名称的第一个字符有些模糊。所以我在想这可能是导致问题的原因。
有什么建议吗?
编辑
设置表的代码
class ForumTopicWidget(QFrame):
def __init__(self,db):
QFrame.__init__(self)
self._db=db
self._rowcount = 21
self._current_page = 1
self._forum_id = None
self._category_id = None
self._navigation_widget = NavigationHeadWidget()
self._layout = QVBoxLayout()
self._title_label = QLabel()
self._title_label.setText("<b>Topics</b>")
self._title_label.setAlignment(Qt.AlignCenter)
self._layout.addWidget(self._title_label)
self._layout.addWidget(self._navigation_widget)
self._topic_list = QTableWidget()
#self._topic_list.setMinimumWidth(600)
self._topic_list.setRowCount(self._rowcount)
self._topic_list.setColumnCount(3)
self._topic_list.setHorizontalHeaderLabels(["Name","Posts", "Views"])
self._topic_list.horizontalHeader().setResizeMode(0,QHeaderView.Stretch)
self._topic_list.verticalHeader().setVisible(False)
#self._topic_list.setColumnWidth(0,476)
self._topic_list.setColumnWidth(1,61)
self._topic_list.setColumnWidth(2,61)
self._topic_list.setSelectionBehavior(QAbstractItemView.SelectRows)
self._layout.addWidget(self._topic_list)
self.setLayout(self._layout)
self.setFrameStyle(QFrame.WinPanel)
self._topic_list.cellClicked.connect(self.cell_clicked)
self._navigation_widget.set_nav_functions(self._shift_first,
self._shift_prev,
self._shift_next,
self._shift_last)
self.page_ids = []
def cell_clicked(self,item):
self._prime_topic(self.page_ids[item])
def set_item_click_function(self,function):
self._prime_topic = function
def set_initial_state(self, category_id, forum_name):
self._category_id = category_id
self._topic_count = self._db.get_topic_count(category_id)
self._last_page = int(ceil(float(self._topic_count) / self._rowcount))
self.shift_state(1)
self._title_label.setText("<b> %s Topics</b>" % forum_name)
def shift_state(self, new_page):
self._current_page = new_page
self.populate_page(new_page)
self._navigation_widget.set_pagination_string(self._current_page,
self._last_page)
def _shift_first(self):
self.shift_state(1)
self._current_page = 1
def _shift_prev(self):
if self._current_page != 1:
self._current_page = self._current_page - 1
self.shift_state(self._current_page)
def _shift_next(self):
if self._current_page != self._last_page:
self._current_page = self._current_page + 1
self.shift_state(self._current_page)
def _shift_last(self):
self.shift_state(self._last_page)
def populate_page(self,page_number):
pages = self._db.get_paginated_topics(self._category_id,page_number,self._rowcount);
i=0
self.page_ids[:]=[]
for page in pages:
self.page_ids.append(page.id)
q = QLabel()
q.setText('<font size ="3">%s</font>' % page.title)
self._topic_list.setCellWidget(i,0, q)
pc = QTableWidgetItem(str(page.post_count))
vc = QTableWidgetItem(str(page.view_count))
pc.setFlags(QtCore.Qt.ItemIsEnabled)
#pc.setFlags(QtCore.Qt.ItemIsEnabled)
self._topic_list.setItem(i,1, pc)
self._topic_list.setItem(i,2, vc)
i = i +1
问题出现在 OS X 和 Linux 上。