我有以下扩展类QListWidget
,但我似乎无法将doubleClicked
信号连接到我想要的插槽。这是在 VS2012 中实现的代码。这个想法是能够双击一个项目并对其进行编辑。我将信号连接到构造函数中的插槽,但是当我通过调试器运行它时,从未调用过该插槽。
# .h file
class DisplayFeed :
public QListWidget
{
Q_OBJECT
public:
DisplayFeed(QWidget *parent, Logic *logic, int xpos, int ypos, int width, int height, std::string color);
~DisplayFeed(void);
void setColor(std::string color);
void refresh(std::vector<Event*> *thingsToInclude);
private:
Logic* logic;
private slots:
void editItem(QEventStore *item);
};
下面是 .cpp 文件。QEventStore
延伸QListWidgetItem
。我也放置了 MessageBox 来测试系统,以防我的其他代码不起作用。
# .cpp file, only relevant methods included
DisplayFeed::DisplayFeed(QWidget *parent, Logic *logic, int xpos, int ypos, int width, int height, std::string color)
: QListWidget(parent)
{
this->logic = logic;
setGeometry(xpos, ypos, width, height);
setColor(color);
QObject::connect(this, SIGNAL(itemClicked(QEventStore*)), this, SLOT(editItem(QEventStore*)));
show();
}
void DisplayFeed::editItem(QEventStore *item){
QMessageBox::information(this,"Hello!","You clicked \""+item->text()+"\"");
QEventEditor *editor = new QEventEditor(item->getEvent());
}