PDA

View Full Version : example using Qwindow



PstdEr
13th June 2013, 10:31
Hi,

i have written a sample program using Qwindow.
i would like to set some color or add some image to QWindow, but as soon as i run the program the window is opening with background color of other below windows , in my case i m opening from qtcreator,so the window is opening with qtcrator background.


hellotest.cpp



#include "hellotest.h"

HelloTest :: HelloTest(QWindow *parent):
QWindow(parent)

{
QWidget *cont = new QWidget;
QVBoxLayout *vl = new QVBoxLayout;
qDebug() << "in hello test";
//QWidget *window = new QWidget(parent);
//QProcess *process = new QProcess(this);
QStringList args;
//args<<"-style"<<"fusion";
//process->start("../../sample-build-Qt5_1Alpha-Debug/sample");//,args);

QWidget *window = new QWidget ;//::createWindowContainer(this,0,0);
window -> resize(500,500);
window ->setPalette(QPalette(QColor(255,0,0,255)));
//setIcon(QIcon("/home/ramu/Pictures/screen.png"));
//window -> setPalette(QPalette(QColor(0,255,0,255)));
//window -> setAutoFillBackground(true);
cont -> setLayout(vl);
vl -> addWidget(window);
}

HelloTest::~HelloTest()
{

}



hellotest.h



#ifndef HELLOTEST_H
#define HELLOTEST_H

#include <QtWidgets/QWidget>
#include <QDebug>
#include <QtX11Extras/qx11info_x11.h>
#include <QtWidgets/QApplication>
#include <QtWidgets/QVBoxLayout>
#include <QWindow>
#include<QProcess>

class HelloTest :public QWindow
{
Q_OBJECT

public:
HelloTest(QWindow *parent = 0);
~HelloTest();
private:



};

#endif // HELLOTEST_H



main.cpp



#include "hellotest.h"
//QX11EmbedWidget *embed;
QWindow *embed;
//QWidget * embed;
HelloTest *hellotest;

int main(int argc, char *argv[])
{
QApplication qapp(argc, argv);
QString windowId(qapp.arguments()[1]);
QVBoxLayout* layout = new QVBoxLayout;

//embed = new QWidget;
embed = new QWindow;
// embed -> setMinimumSize(500,500);
embed -> resize(500,500);
// embed ->setIcon(QIcon("/home/Pictures/screen.png"));
//embed -> setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Expanding);

//embed -> setPalette(QColor(255,0,0,255));

//embed -> setAutoFillBackground(true);

hellotest = new HelloTest(embed);
//hellotest -> setContentsMargins(0,0,0,0);

if(NULL == embed)
{
qDebug() << "Unable to create hellotest";
return 0;
}
if(argc < 2)
{
qDebug() << "More Arguments Needed";
return 0;
}
qDebug()<<"windowId in WG:"<<windowId;

//layout -> addWidget(hellotest);
//embed -> setLayout(layout);
// embed -> embedInto(windowId.toULong());
// embed ->fromWinId(windowId.toULong());
// embed -> setVisible(true);
embed -> show();
return qapp.exec();
}

anda_skoa
13th June 2013, 12:00
You are creating widgets but not showing them.

Cheers,
_

PstdEr
13th June 2013, 12:32
Hi anda_skoa
i am in the process of converting my Qt4 related code to Qt5 in below thread.

can you please look at it and guide me .

thanks

http://www.qtcentre.org/threads/54922-Qt5-and-embedwidgets

anda_skoa
13th June 2013, 14:55
Ah.

I think in both applications you would just use normal QWidgets.
In the one that is the container you create a window using fromWinId() and embed that into your widget using createWindowContainer.

Haven't tried that myself yet, but that is how I would approach it.

Cheers,
_

PstdEr
14th June 2013, 14:31
Hi anda_skoa,

I have update with the new code.

if possible have a look and let me know if you have any points.

http://www.qtcentre.org/threads/54922-Qt5-and-embedwidgets?p=245934#post245934

Thanks,