English 中文(简体)
让“ WebView” 在鼠标轮上水平滚动
原标题:let `QWebView` scroll horizontally on mouse wheel
  • 时间:2012-05-23 13:36:14
  •  标签:
  • qt
  • qwebview

水平滚动而不是在鼠标轮事件中垂直滚动最简单的方式是什么。 我可以想到以下的替代方法, 但也许有比较简单的方法 :

  1. subclass QWebView and reimplement QWebView::wheelEvent()
  2. load some javascript on the displayed page which does the transformation
问题回答

另一种方法是发送带有定向水平的假车轮活动。

void HScrollWebView::wheelEvent(QWheelEvent *ev)
{
  QWheelEvent weHorizontal( ev->pos(), ev->delta(), ev->buttons(), ev->modifiers(), 
                            Qt::Horizontal );
  QWebView::wheelEvent( &weHorizontal );
}

此版本也适用于复杂的网页。 例如, 带有可滚动分节的网页不会通过调用

page()->currentFrame()->scroll(ev->delta(), 0);

如果当前Frame () 指向错误的框架( 如主机) 。

在我的问题中,我高估了备选方案1的复杂性。

class HScrollWebView : public QWebView
{
     Q_OBJECT
public:
     explicit HScrollWebView(QWidget *parent = 0);
protected:
     virtual void wheelEvent(QWheelEvent *ev);
};

void HScrollWebView::wheelEvent(QWheelEvent *ev){
     page()->currentFrame()->scroll(ev->delta(), 0);
}




相关问题
Qt: Do events get processed in order?

If I had a class A, where one of its functions does: void A::func() { emit first_signal(); emit second_signal(); } Assuming that a class B has 2 slots, one connected to first_signal, and the ...

How to determine how much free space on a drive in Qt?

I m using Qt and want a platform-independent way of getting the available free disk space. I know in Linux I can use statfs and in Windows I can use GetDiskFreeSpaceEx(). I know boost has a way, ...

Drag & drop with .ui files

I m having big troubles with drag & drop. I ve created a new Qt Designer Form Class in which I have one QListWidget and one QWidget. Now I want to enable dragging & dropping between these two ...

Link errors on Snow Leopard

I creating a small desktop application using Qt and Poco on Mac OS X Snow Leopard. Qt works fine, but once I started linking with Poco I get the following warning: ld: warning: in /Developer/SDKs/...

Showing two windows in Qt4

My friend and I have each created parts of a GUI using Qt 4. They both work independently and I am trying to integrate his form with the my main window. As of now this is the code I am using to try ...

Qt equivalent of .NET data binding?

Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...

热门标签