[Interest] Best way to get a QWidget from a device context (HDC)

Andreas Pakulat apaku at gmx.de
Thu Jan 8 00:00:18 CET 2015


Hi Jason,

On Wed, Jan 7, 2015 at 9:16 PM, Jason Dolan <jason at pcc.com> wrote:

> I’m stuck with some 3rd party code where the input is a device context
> (HDC), and I need to get the widget it’s associated with.
>
> My current implementation (completely untested as of yet) is:
>
> QWidget *w = QWidget::find((WId)WindowFromDC(hDC));
>
>
> #1: I’m not even sure this will work (although I think it will) — I’m
> coding under OS X right now and will have to test on our windows build
> machine in a bit
> #2: This needs to be as fast as possible as this can be called ALOT.  Any
> time the function says “find” I get worried about speed…
>
> Does anyone know if there is a more efficient/better solution for
> obtaining a Widget given a device context?
>

No idea about #1 but #2 is a lookup in a hash (find is implemented as
QWidgetMapper::value(wId) and QWidgetMapper is a QHash<WId, QWidget*> in
Qt4).

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150108/2b07a0eb/attachment.html>


More information about the Interest mailing list