I have no problems with moving my window, I want to
have an opportunity to resize it!
Here is my code:
myprog.h
#include <QtGui>
#include <QtDeclarative>
class MyProg : public QDeclarativeView
{
Q_OBJECT
public:
~MyProg();
Q_INVOKABLE void moveWindow(int x,int y, int, int);
};
#include <QtGui>
#include <QtDeclarative>
class MyProg : public QDeclarativeView
{
Q_OBJECT
public:
MyProg(QWidget *parent = 0);
~MyProg();
Q_INVOKABLE void moveWindow(int x,int y, int, int);
};
To copy to clipboard, switch view to plain text mode
myprog.cpp
#include "myprog.h"
// : QWidget(parent,0)
: QDeclarativeView(parent)
{
rootContext()->setContextProperty("mainwnd",this);
setResizeMode(QDeclarativeView::SizeRootObjectToView);
setSource
(QUrl("qml/main.qml"));
}
MyProg::~MyProg()
{
}
void MyProg::moveWindow(int x,int y, int lx, int ly)
{
p.setX(p.x() - lx);
p.setY(p.y() - ly);
this->move(p);
}
#include "myprog.h"
MyProg::MyProg(QWidget *parent)
// : QWidget(parent,0)
: QDeclarativeView(parent)
{
rootContext()->setContextProperty("mainwnd",this);
setResizeMode(QDeclarativeView::SizeRootObjectToView);
setSource(QUrl("qml/main.qml"));
}
MyProg::~MyProg()
{
}
void MyProg::moveWindow(int x,int y, int lx, int ly)
{
QPoint p = mapToGlobal(QPoint(x,y));
p.setX(p.x() - lx);
p.setY(p.y() - ly);
this->move(p);
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QtGui/QApplication>
#include "myprog.h"
int main(int argc, char *argv[])
{
MyProg w;
w.setWindowFlags(Qt::FramelessWindowHint) ;
w.setAttribute(Qt::WA_TranslucentBackground);
w.setStyleSheet("background:transparent");
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "myprog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyProg w;
w.setWindowFlags(Qt::FramelessWindowHint) ;
w.setAttribute(Qt::WA_TranslucentBackground);
w.setStyleSheet("background:transparent");
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
It seems to me, that I must catch the press button event in qml code first, and then calculate QDeclarativeView window geometry in my cpp code...
something like that,I think.
Bookmarks