Hey guys,
i created an own QTableWidgetItem:
Header:
struct Connections{
int connection;
};
{
public:
MyQTableWidgetItem();
void setConnection(MyQTableWidgetItem &connectedItem, int connection);
private:
QVector <Connections
*> ConnectedItems;
signals:
public slots:
};
struct Connections{
QTableWidgetItem *connectedItem;
int connection;
};
class MyQTableWidgetItem : public QTableWidgetItem
{
public:
MyQTableWidgetItem();
void setConnection(MyQTableWidgetItem &connectedItem, int connection);
private:
QVector <Connections*> ConnectedItems;
signals:
public slots:
};
To copy to clipboard, switch view to plain text mode
Source:
#include "myqtablewidgetitem.h"
MyQTableWidgetItem::MyQTableWidgetItem()
{
}
void MyQTableWidgetItem::setConnection(MyQTableWidgetItem &connectedItem, int connection)
{
bool itemFound = false;
for(int i = 0;i < this->ConnectedItems.length();i++){
if(this->ConnectedItems[i]->connectedItem->text() == connectedItem.text()){
this->ConnectedItems[i]->connection = connection;
itemFound = true;
i = this->ConnectedItems.length();
}
}
if(!itemFound){
Connections *newConnection = new Connections;
newConnection->connectedItem = &connectedItem;
newConnection->connection = connection;
this->ConnectedItems << newConnection;
}
}
#include "myqtablewidgetitem.h"
MyQTableWidgetItem::MyQTableWidgetItem()
{
}
void MyQTableWidgetItem::setConnection(MyQTableWidgetItem &connectedItem, int connection)
{
bool itemFound = false;
for(int i = 0;i < this->ConnectedItems.length();i++){
if(this->ConnectedItems[i]->connectedItem->text() == connectedItem.text()){
this->ConnectedItems[i]->connection = connection;
itemFound = true;
i = this->ConnectedItems.length();
}
}
if(!itemFound){
Connections *newConnection = new Connections;
newConnection->connectedItem = &connectedItem;
newConnection->connection = connection;
this->ConnectedItems << newConnection;
}
}
To copy to clipboard, switch view to plain text mode
Now I place this items into a table:
Header:
{
Q_OBJECT
public:
AnalyseTable
(QWidget * parent
= 0);
private:
bool lastRowUsed();
signals:
public slots:
void InsertNewRow();
};
#endif // ANALYSETABLE_H
class AnalyseTable : public QTableWidget
{
Q_OBJECT
public:
AnalyseTable(QWidget * parent = 0);
private:
bool lastRowUsed();
signals:
void createNewButton(QTableWidgetItem &item);
public slots:
void InsertNewRow();
};
#endif // ANALYSETABLE_H
To copy to clipboard, switch view to plain text mode
Source:
#include "analysetable.h"
#include <QDebug>
{
this->setColumnCount(6);
}
bool AnalyseTable::lastRowUsed()
{
int rows = this->rowCount();
if(!rows){
return true;
}
if(this->item(rows - 1,0)->text() == "")
return false;
return true;
}
void AnalyseTable::InsertNewRow()
{
if(this->lastRowUsed()){
int rows = this->rowCount();
this->insertRow(rows);
int column = this->columnCount();
for(int i = 0 ; i< column; i++){
this->setItem(rows,i,new MyQTableWidgetItem());
}
emit createNewButton(*(this->item(rows,0)));
}
}
#include "analysetable.h"
#include <QDebug>
AnalyseTable::AnalyseTable(QWidget *parent) : QTableWidget(parent)
{
this->setColumnCount(6);
}
bool AnalyseTable::lastRowUsed()
{
int rows = this->rowCount();
if(!rows){
return true;
}
if(this->item(rows - 1,0)->text() == "")
return false;
return true;
}
void AnalyseTable::InsertNewRow()
{
if(this->lastRowUsed()){
int rows = this->rowCount();
this->insertRow(rows);
int column = this->columnCount();
for(int i = 0 ; i< column; i++){
this->setItem(rows,i,new MyQTableWidgetItem());
}
emit createNewButton(*(this->item(rows,0)));
}
}
To copy to clipboard, switch view to plain text mode
My problem now:
emit createNewButton(*(this->item(rows,0)));
this->item() doesnt retrun a MyQTableWidgetItem it return a QTableWidgetItem. How can i fix that? Someone got an idea?
Greets
Bookmarks