I've searched the docs and the forums but can't figure out how to do this.
I open a new project in Qt Creator 4.0.2 and add one pushbutton to the form. When I click the pushbutton, I want the entire form to move to ( 100, 100 ).
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
w.move( 100, 100 );
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
w.move( 100, 100 );
}
To copy to clipboard, switch view to plain text mode
The last line, "w.move( 100, 100 ); doesn't work, of course, because w is defined in main.cpp, not mainwindow.cpp.
Substituting "ui" for "w" also doesn't work because there is no "move" function for ui.
"ui->centralWidget->move( 100, 100 );" works but it only moves the central widget, not the window.
What am I missing?
Bookmarks