PDA

View Full Version : h0w i can get a browser window on selection of item from tree-widget(item-based)



jyoti
7th November 2006, 11:44
hi all

i want to know the code for view like this

parent1
:
:------------>sub11
:------------>sub12
parent2
:
:------------>sub21
:------------>sub22
.
.
.
so on


i want that when i select sub11 then an external page should be opened like"google.com"
n when i select sub22 then another external page should be opened"qtforum.org"

plz tell me as soon as possible
thanks in advance

jpn
7th November 2006, 12:05
Create a custom slot and connect it to:
void QTreeWidget::itemClicked(QTreeWidgetItem* item, int column) [signal]

In the slot, use QDesktopServices (new in Qt 4.2) to open the URL.

Btw, how is this related to Qt Designer?

sunil.thaha
7th November 2006, 12:12
To add to that

When you add items to the Tree. Have the items associatd to an Url using
QTreeViewItem::setData function

On item clicked you can retreive the url and use QDesktopServices or QTextBrowser for the display

e8johan
7th November 2006, 12:34
Connect a slot showing the page to the QAbstractItemView::clicked ( const QModelIndex & index ) signal from your TreeView/Widget.

jyoti
7th November 2006, 13:02
i had checked already not even giving error but these are not working
coding s like

void form1::showResult(QTreeWidgetItem * item, int column)
{
QString str,str1;
str=item->text(0);

if(str.compare("sub11")==0)

{
QUrl url("http://www.google.com");
}

its not working on selected event of sub11


so plz suggest me for coding in "if " part

jacek
7th November 2006, 16:34
Please don't start more than one thread on the same topic. Threads merged.

jyoti
8th November 2006, 06:46
all signal n slots are working properly...even not giving an error but problem is still a problem
plz help me out to solve it....

i want a internet browser page on selection of "sub11"

plz help as soon as possible

jpn
8th November 2006, 07:56
Are you using Qt 4.2? Did you read about QDesktopServices which was already suggested in earlier posts?

If you are using an earlier version of Qt, try searching the forums. This subject has been discussed several times, like for example in this thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-qt41how-to-make-links-open-browsers-233.html).

wysota
8th November 2006, 09:09
QUrl url("http://www.google.com");
== snip ==
so plz suggest me for coding in "if " part

I suggest you take a look at QUrl docs and read what the class is meant to do. Trying random classes won't help you much...



str.compare("sub11")==0
And what is this? How about:
if(str=="sub11") ...?

jyoti
8th November 2006, 11:19
i m using qt4.2 designer....(ui is attached) on MAC OS


if(str1=='sub1') is equally same as i mentioned wid compare..

n again asking problem is
when i click to 'sub1'
then a page"google.com" should be opened in textbrowser
plz suggest its coding
my mail address jyoti.verma@stellarinfo.com

wysota
8th November 2006, 12:01
QDesktopServices::openUrl().

jyoti
8th November 2006, 12:33
my coding part:


void form1::showResult(QTreeWidgetItem * item, int column)
{
QString str,str1;
str=item->text(0);

if(str.compare("sub1")==0)

{
QUrl myurl;
myurl=QUrl::fromEncoded("http://www.google.com");
textBrowser->setSource(myurl);

}

form1 is my name of form

so plz suggest me best fit coding
as u say QDesktopServices::
as i find openURl() take bool value...

wysota
8th November 2006, 14:18
as i find openURl() take bool value...
?????????????????????????????

AFAIK this method takes a QUrl argument...


QDesktopServices::openUrl(QUrl("http://www.qtcentre.org"));

jyoti
9th November 2006, 06:27
thank u very much...:)


but can u plz help me abt this type of another query...
if my file is placed on my desktop n i want the same...
means on selection of "sub11"
a help folder should be opened..which is placed on my desktop...

plz do help me out....as soon as possible

thanks in advance

wysota
9th November 2006, 08:35
Just change the URL to point to the file you wish to open. QUrl::fromLocalFile() may be handy.