本文整理汇总了C++中QWebElement::setFocus方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebElement::setFocus方法的具体用法?C++ QWebElement::setFocus怎么用?C++ QWebElement::setFocus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebElement
的用法示例。
在下文中一共展示了QWebElement::setFocus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: click
int PhpWebView::click(const QString & xpath, bool samewnd)
{
QWebElement elem = getElementByXPath(QString(xpath));
if (elem.isNull())
return 0;
elem.setFocus();
if (samewnd)
elem.removeAttribute("target");
QString js = "var node = this; var x = node.offsetLeft; var y = node.offsetTop; ";
js += "var w = node.offsetWidth/2; ";
js += "var h = node.offsetHeight/2; ";
js += "while (node.offsetParent != null) { ";
js += " node = node.offsetParent; ";
js += " x += node.offsetLeft; ";
js += " y += node.offsetTop; ";
js += "} ";
js += "[x+w, y+h]; ";
QList<QVariant> vlist = elem.evaluateJavaScript(js).toList();
QPoint point;
point.setX(vlist.at(0).toInt());
point.setY(vlist.at(1).toInt());
QRect elGeom = elem.geometry();
QPoint elPoint = elGeom.center();
int elX = point.x(); //elPoint.x();
int elY = point.y(); //elPoint.y();
int webWidth = width();
int webHeight = height();
int pixelsToScrollRight=0;
int pixelsToScrollDown=0;
if (elX > webWidth)
pixelsToScrollRight = elX-webWidth+elGeom.width()/2+50; //the +10 part if for the page to scroll a bit further
if (elY > webHeight)
pixelsToScrollDown = elY-webHeight+elGeom.height()/2+50; //the +10 part if for the page to scroll a bit further
/*pixelsToScrollRight = elX-elGeom.width()/2-50;
pixelsToScrollDown = elY-elGeom.height()/2-50;
if (pixelsToScrollRight < 0)
pixelsToScrollRight = 0;
if (pixelsToScrollRight > page()->mainFrame()->scrollBarMaximum(Qt::Horizontal))
pixelsToScrollRight = page()->mainFrame()->scrollBarMaximum(Qt::Horizontal);
if (pixelsToScrollDown < 0)
pixelsToScrollDown = 0;
if (pixelsToScrollDown > page()->mainFrame()->scrollBarMaximum(Qt::Vertical))
pixelsToScrollDown = page()->mainFrame()->scrollBarMaximum(Qt::Vertical);*/
int oldHoriz = page()->mainFrame()->scrollBarValue(Qt::Horizontal);
int oldVert = page()->mainFrame()->scrollBarValue(Qt::Vertical);
page()->mainFrame()->setScrollBarValue(Qt::Horizontal, pixelsToScrollRight);
page()->mainFrame()->setScrollBarValue(Qt::Vertical, pixelsToScrollDown);
QPoint pointToClick(elX-pixelsToScrollRight, elY-pixelsToScrollDown);
QEventLoop loop;
isNewViewCreated = false;
isNewViewBegin = false;
//QMouseEvent *pressEvent = new QMouseEvent(QMouseEvent::MouseButtonPress, pointToClick, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
//QApplication::postEvent(browser, pressEvent);
//QApplication::processEvents();
//QMouseEvent releaseEvent(QMouseEvent::MouseButtonRelease,pointToClick,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
//QApplication::sendEvent(browser, &releaseEvent);
QString js2 = "var e = document.createEvent('MouseEvents');";
//js2 += "e.initEvent( 'click', true, true );";
//js2 += "e.initMouseEvent('click', true, true, window, 0, 0, 0, "+QString::number(elX)+", "+QString::number(elY)+", false, false, false, false, 0, null);";
js2 += "e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);";
js2 += "this.dispatchEvent(e);";
elem.evaluateJavaScript(js2);
QTimer::singleShot(1000, &loop, SLOT(quit()));
loop.exec();
while (browser && isNewViewBegin && !isNewViewCreated)
loop.processEvents();
//page()->mainFrame()->setScrollBarValue(Qt::Horizontal, oldHoriz);
//page()->mainFrame()->setScrollBarValue(Qt::Vertical, oldVert);
return 1;
}