Results 1 to 2 of 2

Thread: How do i make my text in QStandardItem to link to open default browser?

  1. #1
    Join Date
    May 2009

    Default How do i make my text in QStandardItem to link to open default browser?

    Im using QStandardItem as my model items . i was reading about QStyledItemDelegate to manipulate manipulate 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

  2. #2
    Join Date
    Mar 2011
    Thanked 10 Times in 9 Posts
    Qt products
    MacOS X Windows

    Default Re: How do i make my text in QStandardItem to link to open default browser?

    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)

    Qt Code:
    1. QStandardItem* item = new QStandartItem("my text");
    2. item->setData("", Qt::UserRole);
    4. ...
    6. void onItemClicked(QListWidgetItem * item)
    7. {
    8. QString mylink = item->data(Qt::UserRole).toString();
    9. QDesktopServices::openUrl(QUrl(mylink));
    10. }
    To copy to clipboard, switch view to plain text mode 

    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)

Similar Threads

  1. Replies: 0
    Last Post: 17th March 2011, 03:17
  2. Replies: 1
    Last Post: 20th December 2010, 21:48
  3. Open URL on Non Default Browser
    By sheeeng in forum Qt Programming
    Replies: 3
    Last Post: 27th July 2009, 07:34
  4. add link that open web browser on unix
    By asafb in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2009, 21:55
  5. Text Browser Link Question
    By taylor34 in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2006, 19:54


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.