PDA

View Full Version : How do i make my text in QStandardItem to link to open default browser?



umen
8th July 2011, 14:18
Im using QStandardItem as my model items . i was reading about QStyledItemDelegate to manipulate manipulate (http://www.qtcentre.org/threads/22863-HTML-and-QStandardItem)the item’s but im not sure it the right answer to my problem . and if it is .
how should my paint method should look like to be able me to make the text clickable
and open the pc default browser with a link

Berryblue031
11th July 2011, 12:50
I am not sure what kind of widget you are using with your QStandardItems but I don't think you want to use a delegate in this situation simply listen for the QListWidget/QTreeWidget/QTableWidget::itemClicked ( QListWidgetItem * item ) signal
(most of the widgets that inherit QAbstractItemView provide a similar signal)


QStandardItem* item = new QStandartItem("my text");
item->setData("www.mylink.com", Qt::UserRole);

...

void onItemClicked(QListWidgetItem * item)
{
QString mylink = item->data(Qt::UserRole).toString();
QDesktopServices::openUrl(QUrl(mylink));
}

Generally you only need to use an item delegate if you want to display the items differently (like with an icon and on multiple lines etc)