Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Where's the Widget Window?

  1. #1
    qtoptus Guest

    Default Re: Where's the Widget Window?

    I'm using Qt 5.0 which I compiled for VS2008.

    When I use this inside the constructor of an object derived from QWidget or even inside the paint event it returns NULL

    QWindow *window = windowHandle();

    Where's the window? When is it created?


    Added after 1 42 minutes:


    Ok I just found in the documentation this function is in progress...but they don't provide any work around...so
    Last edited by qtoptus; 23rd March 2013 at 22:23.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: Where's the Widget Window?

    so unless we know what you are trying to do, we can't suggest any work around, can we?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Where's the Widget Window?

    That function does not create or display anything: it returns a handle to a related object.

    If you are after the native window handle for an API call then you probably want winId(). I do not expect that winId() returns a valid handle until after the QWidget is shown, i.e. not in the constructor, and not unles the widget is a top level widget.

  4. #4
    qtoptus Guest

    Default Re: Where's the Widget Window?

    I'm creating an OpenGL QWidget, and I need the QWindow object so that I can setFormat of the window, using the new Qt5 OpenGL classes.

    windowHandle() is supposed to return the QWindow object associated with the widget. I don't understand where's the problem it's incomplete.

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

    Default Re: Where's the Widget Window?

    Use QGLWidget::context() and QGLContext::setFormat().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Where's the Widget Window?

    The docs do not say the function is not working, just that the platform abstraction code underlying the QWindow is a work in progress and subject to change. Given that a QWindow represents the underlying OS window it seems very unlikely that such an object exists before the top level QWidget is displayed, i.e. not available in the constructor. Have you looked after the widget is on screen?

    Have you looked at the use of QWindow in the OpenGL Window Example?

  7. #7
    qtoptus Guest

    Default Re: Where's the Widget Window?

    I think I'm not making myself clear. First I'm not going and will never use to anything other than the new Qt5 QOpenGLxxxxx classes.

    I already mentioned the windowHandle() still returns NULL inside the paint event, and yes the windows is already displayed.

    Have you looked at the use of QWindow in the OpenGL Window Example?
    Yes but I'm using a widget that I can embed anywhere on the forms using the designer, so using a Window control is of no help.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Where's the Widget Window?

    Quote Originally Posted by qtoptus View Post
    First I'm not going and will never use to anything other than the new Qt5 QOpenGLxxxxx classes.
    You already are. QGLWidget doesn't use this API. It uses a wrapper of those classes backward compatible with Qt4. If you wish to use Qt5 OpenGL API then use QWindow and QOpenGLContext. You don't need anything else. There is no point in using QWidget (instead of QGLWidget) and QOpenGLContext. This way you end up rewriting QGLWidget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    qtoptus Guest

    Default Re: Where's the Widget Window?

    This way you end up rewriting QGLWidget.
    But this is the only way I can create a designer plugin widget.

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

    Default Re: Where's the Widget Window?

    You can use QGLWidget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    qtoptus Guest

    Default Re: Where's the Widget Window?

    Well my advice is to the team, work on this issue, fix it, and then release please.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Where's the Widget Window?

    Quote Originally Posted by qtoptus View Post
    Well my advice is to the team, work on this issue, fix it, and then release please.
    What issue? There is no "issue" here.

    Qt Code:
    1. /*!
    2.   \preliminary
    3.  
    4.   Returns the QPlatformWindow this widget will be drawn into.
    5. */
    6. QWindow *QWidget::windowHandle() const
    7. {
    8. Q_D(const QWidget);
    9. QTLWExtra *extra = d->maybeTopData();
    10. if (extra)
    11. return extra->window;
    12.  
    13. return 0;
    14. }
    To copy to clipboard, switch view to plain text mode 

    I don't see any "issue" here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    qtoptus Guest

    Default Re: Where's the Widget Window?

    The "issue" is that function does not work!

  14. #14
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Where's the Widget Window?

    Now, where would I have gotten the idea that the function works...
    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QWindow>
    4. #include <QTimer>
    5. #include <QDebug>
    6.  
    7. class Widget: public QWidget
    8. {
    9. Q_OBJECT
    10. public:
    11. Widget(QWidget *p = 0): QWidget(p) {
    12. qDebug() << "Start constructor" << windowHandle();
    13. setWindowTitle("A Cool Title"); // this triggers OS window creation
    14. qDebug() << "End constructor" << windowHandle();
    15. QTimer::singleShot(0, this, SLOT(report()));
    16. }
    17.  
    18. public slots:
    19. void report() {
    20. qDebug() << "After show()" << windowHandle();
    21. if (windowHandle())
    22. qDebug() << "QWindow::title()" << windowHandle()->title();
    23. }
    24.  
    25. protected:
    26. void paintEvent(QPaintEvent *event) {
    27. qDebug() << "In paintEvent()" << windowHandle();
    28. QWidget::paintEvent(event);
    29. }
    30.  
    31. };
    32.  
    33. int main(int argc, char **argv)
    34. {
    35. QApplication app(argc, argv);
    36. Widget w;
    37. w.show();
    38. return app.exec();
    39. }
    40. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    On Linux
    Qt Code:
    1. Start constructor QObject(0x0)
    2. End constructor QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
    3. After show() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
    4. QWindow::title() "A Cool Title"
    5. In paintEvent() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
    6. In paintEvent() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
    To copy to clipboard, switch view to plain text mode 
    On Windows 7 using Qt 5.0.1 MingW build:
    Qt Code:
    1. Z:\uu>qmake -v
    2. QMake version 3.0
    3. Using Qt version 5.0.1 in C:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib
    4.  
    5. Start constructor QObject(0x0)
    6. End constructor QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
    7. After show() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
    8. QWindow::title() "A Cool Title"
    9. In paintEvent() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
    10. In paintEvent() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Where's the Widget Window?

    Quote Originally Posted by qtoptus View Post
    The "issue" is that function does not work!
    For me it doesn't really matter if it "works" or not. What you are trying to do is plain wrong. Instead of using a given API that works, you are trying to sort of "reimplement" it in a way that most probably will start breaking everything else you have. If you start changing QWindow instance your widget draws on then you may break all other widgets working on the same QWindow that expect completely different settings than what you are trying to apply. QWidget uses a raster paint engine and expects a raster based window, QGLWidget uses an OpenGL paint engine and is probably somehow rigged in Qt5 to work with a raster QWindow. If you simply put OpenGL code in a raster QWindow then most probably it will simply not work, if you start modifying things behind Qt's back to "fix" it (e.g. by changing the window to be gl-based), then most probably all other things will stop working.

    You claim you need to do it because of some Designer plugin that supposedly "doesn't work" so maybe you should focus on making it work instead of working around Qt's architecture. I don't think there are any problems in making a designer plugin that is based on QGLWidget so if it doesn't work for you then most probably you somehow goofed it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    qtoptus Guest

    Default Re: Where's the Widget Window?

    If you start changing QWindow instance your widget draws on then you may break all other widgets working on the same QWindow that expect completely different settings than what you are trying to apply.
    I did this successfully in Qt 4.8 with a custom widget that supports Direct3D rendering. So I don't think this is a hack to customize widgets, this is the heart of OOP. Besides they would not expose the QWindow object through windowHandle() if it should not be modified.

    You claim you need to do it because of some Designer plugin that supposedly "doesn't work" so maybe you should focus on making it work instead of working around Qt's architecture.
    The Designer does not allow creation of custom QWindow controls, they have to be widgets. And I'm not going to use the QGLWidget since it's lacking the capabilities of the new QOpenGL classes, such as profiles, recent version of OpenGL, ...etc.

    Now regardless of what I'm trying to do or why this or that way....any idea why windowHandle() returns 0 for a widget?

  17. #17
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Where's the Widget Window?

    Quote Originally Posted by qtoptus View Post
    any idea why windowHandle() returns 0 for a widget?
    It doesn't.

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Where's the Widget Window?

    Quote Originally Posted by qtoptus View Post
    I did this successfully in Qt 4.8 with a custom widget that supports Direct3D rendering.
    4.8 doesn't use QPA.

    And I'm not going to use the QGLWidget since it's lacking the capabilities of the new QOpenGL classes, such as profiles, recent version of OpenGL, ...etc.
    They are not lacking anything. QGLFormat can set OpenGL version up to 4.3 (which is currently the latest OpenGL version available) and can set the same profiles as the other API. As I said before QGL* classes are wrappers over QOpenGL* classes to provide backward compatibility and allow easy use of OpenGL widgets.

    any idea why windowHandle() returns 0 for a widget?
    It doesn't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    qtoptus Guest

    Default Re: Where's the Widget Window?

    It doesn't.
    It does.

    If you know don't know, there's no need to be goat headed and throw farts in attempt to show others we are making things up and Qt is just perfect.

    BTW don't bother replying to this, I'm not going to open this forum anymore, so...bye!

  20. #20
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Where's the Widget Window?

    You have been provided evidence to demonstrate that the function does, indeed, return real values. All that was required was a counter example that showed under what conditions zero was returned. Too hard I guess. Good luck with your future programming efforts.

Similar Threads

  1. Qt Widget opens in new window
    By spikestar in forum Qt Programming
    Replies: 1
    Last Post: 10th September 2012, 14:32
  2. Add custom Widget into window (not using Designer)
    By invisible_uli in forum Newbie
    Replies: 3
    Last Post: 12th January 2010, 09:31
  3. how to set the widget window aways on the top ?
    By tsuibin in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2009, 08:41
  4. How to show a window widget...
    By agent007se in forum Newbie
    Replies: 3
    Last Post: 20th July 2006, 11:42
  5. open a second window/widget
    By michaelschmid in forum Newbie
    Replies: 2
    Last Post: 10th February 2006, 18:49

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
  •  
Qt is a trademark of The Qt Company.