Search code examples
qtwindowqnx

How to show Qt (widgets) app on QNX based on specific location and size?


I'm trying to make my Qt widgets-based app to run on QNX device on a specific location and size using QWidget::setGeometry(..), but it always get shown in full screen.

The app uses QMainWindow with menu bar and a QGLWidget as the central widget.

The same code running on Linux desktop works fine, positioned based on the provided x & y and with the provided size.

Does the windowing system on QNX not support this? Or is it Qt that does not able to use the windowing system on QNX? Or something else? I don't get it :(

Any help is much appreciated!


Solution

  • The Qt platform plugin is implemented with the platform capabilities and limitations in mind. Seems like QNX only supports window switching, no full fledged window management as you would have in windows or linux, therefore Qt applications are implicitly, and possibly intrinsically full screen.

    If you desire to not have it on the entire screen, just implement a blank main window and position the central widget by having it free floating rather than being put in a layout inside the main window.

    But that doesn't mean you will be able to put more applications on the screen, you will only not be using the entire screen for the one application window it displays. You could fake multiple applications by simply using multiple widgets and implement your own fake window manager, the caveat is you will still be using one process, which may or may not end up being an issue.

    Here is what I mean by a "free floating widget":

    class YourWidget : public QWidget {
        Q_OBJECT
    public:
        YourWidget(QWidget * p) : QWidget(p) { resize(100, 100); }
        void paintEvent(QPaintEvent *) {
            QPainter p(this);
            p.fillRect(rect(), Qt::black);
        }
    };
    
    class MainWindow : public QMainWindow {
        Q_OBJECT
    public:
        MainWindow(QWidget *parent = 0) : QMainWindow(parent) {
            resize(500, 500);
            QWidget * blank = new QWidget;
            setCentralWidget(blank);
            widget = new YourWidget(blank);
            widget->move(rect().center());
        }
    
        void mousePressEvent(QMouseEvent * e) {
            widget->move(e->pos());
        }
    private:
        YourWidget * widget;
    };
    

    YourWidget is no longer anchored by a layout, it is free to move to arbitrary position, it is still drawn in the confines of its container widget, which is just a blank widget set as the window's central widget and lifetime is also managed automatically.