PDA

View Full Version : Is overlapping layer possible in qt layouts?



sevketk
19th July 2020, 18:08
I have game , I use layout for diffent screen resolution device. so far so good. but If use a layout , not use overlapping widget
for example my game screen shoot this , and all widget place from layout.
13496

if I wantto show money flush animation movie .gif full screen (over game screen, trasnparent widget) I have to add new hidden wigdet in centralwidget. but this widget join in layout and goto screen right side and corrupt its size.
I want it to look like the picture below (if I remove all layouts and set my game single screen resolition this work)

13497

13498

how to do that in layouts.

In summary, I want a widget independent of "layout". absolute position widget in layout.

d_stranz
20th July 2020, 01:14
Maybe you can use a QDialog with no frame and a transparent background instead of a widget? If this animation widget is not displayed all the time, but only when the player gets a bonus or some other special event occurs, then you could use a QDialog that contains a QTimer with a timeout() signal connected to the QDialog's close() slot. In the dialog's showEvent(), start the timer. When the timer times out, the dialog will be closed. If you make the main window the dialog's parent, it will be centered in the main window but will not change the layout because it is independent of the layout. You can make the dialog any size you want, so it could cover the entire main window or just part of it.

sevketk
21st July 2020, 09:01
First of All. Thank for reply and time d_stranz

I was using QDialog before, but modal QDialog has lots of troubles (eg serialport not work ,defined in mainwindow etc). so it was great for me to use widgets as a QDialog, since I designed 800x600 fixed resolution. but I had to turn the same software into a tablet. When the android tablet resolution was 1280x800, I rearranged the design and added layouts. however, this time dialog widgets became a problem. this is the story of the question.

Qt developers can actually develop widgets that don't depend on layouts. this may be optional. it would be very useful, if not too difficult.

d_stranz
21st July 2020, 16:37
Your QDialog does not have to be modal (which causes other parts of the UI to freeze). If you call QDialog::exec(), then the dialog will be modal. If you create it with a non-modal property (QDialog::setModal() with false), then you can call QDialog::show() and QDialog::hide() and the rest of your UI keeps working.

sevketk
26th July 2020, 12:54
is QDialog responsive?

d_stranz
26th July 2020, 17:56
is QDialog responsive?

I am not sure what you mean. If you post the QDialog as non-modal, using show(), then yes, it will be responsive, but so will the rest of your UI.

sevketk
26th July 2020, 19:10
I am not sure what you mean. If you post the QDialog as non-modal, using show(), then yes, it will be responsive, but so will the rest of your UI.

responsive = It means auto resize , it means , it works on diffent screen resolution devices, proportional size . has it top-level layout?

d_stranz
26th July 2020, 20:02
The behavior is no different from any other dialog. So if you do not set parameters that would keep it from expanding, then it should resize for different screens.

Why don't you just try it instead of asking questions?

sevketk
27th July 2020, 21:53
Ok. I tried. I create with qt creator ui designer new Qdialog
13515

and add one button (preffered size policy) , add layout horizantal and I called it


void MainWindow::on_pushButton_clicked()
{
Dialog myDialog;
myDialog.setModal(false);
myDialog.exec();
}

when I run it , mainwindow occupied the entire screen, but qdialog remained to the extent given. this is result

13516

d_stranz
28th July 2020, 01:28
Why don't you explain exactly what it is you want this dialog to do?

You have set the dialog size to 400 x 300 in Qt Designer, so that is what you see when you call exec(). You did not construct myDialog with the MainWindow instance (this) as the parent, so the dialog is centered on the screen, exactly as it is supposed to be when it it created as a top-level widget (ie. with no parent).

And despite your code calling setModal( false ), when you call exec() it cancels this and displays the dialog as modal. If you want a non-modal dialog, you must use show() and hide().

sevketk
30th July 2020, 11:29
this seems to be the solution for me.


#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
myDialog = new Dialog(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{

//myDialog.setModal(false);
myDialog->showMaximized();
myDialog->raise();

}