Results 1 to 15 of 15

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

  1. #1
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Question h0w i can get a browser window on selection of item from tree-widget(item-based)

    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
    Last edited by jyoti; 7th November 2006 at 11:52.
    thanks & regards
    --------------------
    jyoti

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how i can get a browser window on selection of item from tree-widget(item-based)

    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?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how i can get a browser window on selection of item from tree-widget(item-based)

    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
    We can't solve problems by using the same kind of thinking we used when we created them

  4. #4
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    Connect a slot showing the page to the QAbstractItemView::clicked ( const QModelIndex & index ) signal from your TreeView/Widget.

  5. #5
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: how i can get a browser window on selection of item from tree-widget(item-based)

    i had checked already not even giving error but these are not working
    coding s like
    Qt Code:
    1. void form1::showResult(QTreeWidgetItem * item, int column)
    2. {
    3. QString str,str1;
    4. str=item->text(0);
    5.  
    6. if(str.compare("sub11")==0)
    7.  
    8. {
    9. QUrl url("http://www.google.com");
    10. }
    To copy to clipboard, switch view to plain text mode 

    its not working on selected event of sub11


    so plz suggest me for coding in "if " part
    Last edited by wysota; 8th November 2006 at 09:06. Reason: missing [code] tags
    thanks & regards
    --------------------
    jyoti

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    Please don't start more than one thread on the same topic. Threads merged.

  7. #7
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    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
    thanks & regards
    --------------------
    jyoti

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    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.
    J-P Nurmi

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how i can get a browser window on selection of item from tree-widget(item-based)

    Quote Originally Posted by jyoti View Post
    Qt Code:
    1. QUrl url("http://www.google.com");
    To copy to clipboard, switch view to plain text mode 
    == 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...

    Qt Code:
    1. str.compare("sub11")==0
    To copy to clipboard, switch view to plain text mode 
    And what is this? How about:
    Qt Code:
    1. if(str=="sub11") ...
    To copy to clipboard, switch view to plain text mode 
    ?

  10. #10
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    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
    Attached Files Attached Files
    Last edited by jyoti; 8th November 2006 at 11:45.
    thanks & regards
    --------------------
    jyoti

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)


  12. #12
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    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...
    thanks & regards
    --------------------
    jyoti

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    Quote Originally Posted by jyoti View Post
    as i find openURl() take bool value...
    ?????????????????????????????

    AFAIK this method takes a QUrl argument...

    Qt Code:
    1. QDesktopServices::openUrl(QUrl("http://www.qtcentre.org"));
    To copy to clipboard, switch view to plain text mode 

  14. #14
    Join Date
    Nov 2006
    Location
    gurgaon
    Posts
    49
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    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
    thanks & regards
    --------------------
    jyoti

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: h0w i can get a browser window on selection of item from tree-widget(item-based)

    Just change the URL to point to the file you wish to open. QUrl::fromLocalFile() may be handy.

Bookmarks

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.