Coordinates widget
-
I have this code: ui->dockWidget_2->move(MainWindow::geometry().center());
I'd like to write instead of "center" the coordinates of the widget related to MainWindow..but I can't.. -
I have this code: ui->dockWidget_2->move(MainWindow::geometry().center());
I'd like to write instead of "center" the coordinates of the widget related to MainWindow..but I can't.. -
I have this code: ui->dockWidget_2->move(MainWindow::geometry().center());
I'd like to write instead of "center" the coordinates of the widget related to MainWindow..but I can't..@vale88 Well, you have to do some math here (I assume that "this" is parent of ui->dockWidget_2):
int x = (this->width() - ui->dockWidget_2->width()) / 2; int y = (this ->height() - ui->dockWidget_2->height()) /2; ui->dockWidget_2->move(x, y); -
@vale88 Well, you have to do some math here (I assume that "this" is parent of ui->dockWidget_2):
int x = (this->width() - ui->dockWidget_2->width()) / 2; int y = (this ->height() - ui->dockWidget_2->height()) /2; ui->dockWidget_2->move(x, y);@jsulm said in Coordinates widget:
int x = (this->width() - ui->dockWidget_2->width()) / 2;
int y = (this ->height() - ui->dockWidget_2->height()) /2;
ui->dockWidget_2->move(x, y);it doesn't work, the widget doesn't get its original position
-
@jsulm said in Coordinates widget:
int x = (this->width() - ui->dockWidget_2->width()) / 2;
int y = (this ->height() - ui->dockWidget_2->height()) /2;
ui->dockWidget_2->move(x, y);it doesn't work, the widget doesn't get its original position
-
I have a dockWidget with its original position and then I move it...after that I moved it I want that I press a button and it gets its original position in MainWindow..but I can't, Can you help me?
-
I have a dockWidget with its original position and then I move it...after that I moved it I want that I press a button and it gets its original position in MainWindow..but I can't, Can you help me?
-
@jsulm said in Coordinates widget:
Did you store its original position somewhere
yes but if write move(100, 40) I don't obtain its position relative to MainWindow
-
@jsulm said in Coordinates widget:
Did you store its original position somewhere
yes but if write move(100, 40) I don't obtain its position relative to MainWindow
-
@vale88 I guess because it is inside a widget (central widget) not main window. How do you store original coordinates (can you show the code)?
@jsulm #include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
real_pos= ui->dockWidget_2->mapToGlobal(QPoint(100,40));}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
ui->dockWidget_2->setFloating(true);
}void MainWindow::on_pushButton_2_clicked()
{
ui->dockWidget_2->move(real_pos.x(), real_pos.y());}
-
@jsulm #include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
real_pos= ui->dockWidget_2->mapToGlobal(QPoint(100,40));}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
ui->dockWidget_2->setFloating(true);
}void MainWindow::on_pushButton_2_clicked()
{
ui->dockWidget_2->move(real_pos.x(), real_pos.y());}
-
@vale88 If I don't mistake, you must not use mapToGlobal because it converts widget coordinates to screen coordinates. If you want to move widget relative to MainWindows you must move to 100,40.
So real_pos = QPoint(100, 40);
@CP71 I tried but the problem remains...I have a problem with dockwidget..they stick to mainwindow..so I must do a function with move
-
@CP71 I tried but the problem remains...I have a problem with dockwidget..they stick to mainwindow..so I must do a function with move
-
@CP71 I put dockwidget in a layout of a stacked widget
-
@CP71 I put dockwidget in a layout of a stacked widget
-
@vale88 I suppose that layout is the problem, layout is placing your widget.
This explains because you can't position your widget as you wish.@CP71 I want posizionate my dockwidget wherever I want, but I can't because the dockwidget attached to the MainWindow
-
@CP71 I want posizionate my dockwidget wherever I want, but I can't because the dockwidget attached to the MainWindow