Isolating an element of a QWebView
-
Take a look on "findFirstElement":http://doc.trolltech.com/4.6/qwebframe.html#findFirstElement from "QWebFrame":http://doc.trolltech.com/4.6/qwebpage.html#mainFrame...
It will return a QWebElement, which is probably what you want.
-
@webview->page()->mainFrame()->findFirstElement("#yourID");@
-
i've tried that, but i can't manage to get the other elements to go away when i want them to, and i can't get it to let me insert it back in.
-
Well, I've never tried to do that, but you can try "takeFromDocument()":http://doc.trolltech.com/4.6/qwebelement.html#takeFromDocument
-
so what would the final peice of code look like that would find an element, clear the document, then put the found element back in? (i've tried and can't seem to get my references right)
-
anyone gonna help me at all on this?
-
I think they did give you the solution.
Something like
@a.takeFromDocument();
frame->documentElement()->removeAllChildren();
frame->documentElement()->appendInside(a);@I let you figure out the details.
-
Hopefully what you just gave me will be what i need, (my build machine's ethernet port died :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( so I have to wait till the ethernet card get's get before i can test to see if it works fully) it does at least build without errors after i make a few changes (your -> should be .'s before remove and append) here is the final code i get:
@void Widget::on_Login_Main_loadFinished(bool )
{
QWebFrame *frame = ui->Login_Main->page()->mainFrame();
QWebElement loginbox = frame->findFirstElement("#loginbox");
loginbox.takeFromDocument();
ui->Login_Main->page()->mainFrame()->documentElement().removeAllChildren();
ui->Login_Main->page()->mainFrame()->documentElement().appendInside(loginbox);
}@btw yes, the class name of the element i'm trying to isolate is loginbox :P huzzah for simple names :P and if you see something wrong with the code please point it out :P I can't build it on this comp because i don't have a flash drive, and this takes about 10 minutes to build the program, (and it's only 1k lines, (it takes this computer about 3 hours to configure Qt for building, it takes my build machine about 3-5 minutes) unfortunately my build machine is linux and this is windows, so i can't build it there burn it to a cd then run it here :P)
-
ok, i couldn't it to find a specific class, but here is what i did to get it isolated (and please read after the end of the code, because I have a question about how to do something)
@void Widget::on_Login_prgrs_valueChanged(int value)
{
loginprgrs = value;
ui->actionLoadchanged->trigger();
QWebFrame *frame = ui->Login_Main->page()->mainFrame();
QWebElement doc = frame->documentElement();
QWebElement head = doc.firstChild();
QWebElement body = head.nextSibling();
QWebElement div = body.firstChild();
QWebElement table = div.nextSibling();
QWebElement tbody1 = table.firstChild();
QWebElement tr1 = tbody1.firstChild();
QWebElement td1 = tr1.firstChild();
QWebElement form = td1.firstChild();
QWebElement table2 = form.firstChild();
QWebElement tbody2 = table2.firstChild();
QWebElement tr2 = tbody2.firstChild();
QWebElement td2 = tr2.firstChild();
QWebElement p = td2.firstChild();
QWebElement loginbox = p.nextSibling();
QWebElement p2 = loginbox.nextSibling();
QWebElement script = p2.nextSibling();
QWebElement script2 = script.nextSibling();
QWebElement annoyingbanner = script2.nextSibling();annoyingbanner.removeFromDocument();
}
void Widget::on_Login_Main_loadFinished(bool )
{
QWebFrame *frame = ui->Login_Main->page()->mainFrame();
QWebElement doc = frame->documentElement();
QWebElement head = doc.firstChild();
QWebElement body = head.nextSibling();
QWebElement div = body.firstChild();
QWebElement table = div.nextSibling();
QWebElement tbody1 = table.firstChild();
QWebElement tr1 = tbody1.firstChild();
QWebElement td1 = tr1.firstChild();
QWebElement form = td1.firstChild();
QWebElement table2 = form.firstChild();
QWebElement tbody2 = table2.firstChild();
QWebElement tr2 = tbody2.firstChild();
QWebElement td2 = tr2.firstChild();
QWebElement p = td2.firstChild();
QWebElement loginbox = p.nextSibling();
QWebElement p2 = loginbox.nextSibling();
QWebElement script = p2.nextSibling();
QWebElement script2 = script.nextSibling();
QWebElement noscript = script2.nextSibling();
QWebElement br = noscript.nextSibling();
QWebElement p3 = br.nextSibling();
QWebElement p4 = p3.nextSibling();
QWebElement td3 = td2.nextSibling();
QWebElement tr3 = tr2.nextSibling();
QWebElement div2 = table2.nextSibling();script2.removeFromDocument(); script.removeFromDocument(); noscript.removeFromDocument(); br.removeFromDocument(); p3.removeFromDocument(); p4.removeFromDocument(); p2.removeFromDocument(); p.removeFromDocument(); td3.removeFromDocument(); tr3.removeFromDocument(); div2.removeFromDocument(); div.removeFromDocument();
}@
First off, the second set of variable assignments are different because of the fact that by that time the annoying banner element (which takes about 10-20 seconds to load) is no longer there. Second, the url of the page i'm using is,"here":http://magicduel.com/authentication.php
The question I have is how would I change the width that is set in the first table element? Because, since I've isolated the login box, it justs adds a scrollbar to my qwebview when it's not really needed.
-
anyone have any idea how to get it to let me delete the width attribute? (i can't manage to get it to delete that attribute)