Reputation: 91
I am new in using QT and i have a problem. I want to check a 2D circuit layout and I want to output warnings or errors on a window. Each warning or error should contain X and Y coordinates and when I click on a warning it should call a function which navigates me to the faulty position in the layout(coordinate system).
Is there a way to make a text funcioning ? I hope you understood my problem.
Upvotes: 0
Views: 371
Reputation: 321
Yes, it can be implemented with the QTextBrowser
, but there will be a lot of code and no benefits. There is a faster, simpler and more scalable way.
Just use QListWidget
and set user data (QListWidgetItem::setData
) to each item, that will contain coordinates (you can use QPoint
for this).
Create QListWidget
and connect some slot or function to the signal QListWidget::itemClicked
:
QListWidget* log = new QListWidget;
QObject::connect(log, SIGNAL(itemClicked(QListWidgetItem*)), onItemClicked(QListWidgetItem*));
Then, when you recieve new warning (ex. in QString
called log_string
) with coordinates (called x
and y
):
QListWidgetItem* line = new QListWidgetItem(log_string, log);
line->setData(Qt::UserRole, QVariant(QPoint(x, y)));
log->addItem(line);
Now you only need to process coordinates in the proper way in the slot or function connected to the QListWidget::itemClicked
signal:
void onItemClicked(QListWidgetItem* item)
{
const QPoint coord = item->data(Qt::UserRole).toPoint();
// process coord.x() and coord.y()
}
Upvotes: 1