How to fix the size of MDI Subwindow in Qt - c++

I'm creating a Desktop Application in Qt and I'm showing subwindow inside the MDI Area. I have the problem that in the size of subwindow adjusts every time I open my code in the other monitor.
My goal is to fix the size of subwindow and make it parent size. Hope you understand my problem.
I'm using this code to change the size and showing the subwindow in mdi area
Subwindow1 = new QMdiSubWindow(mdiArea);
QQuickWidget* widget2 = new QQuickWidget(Map);
widget2->setResizeMode(QQuickWidget::SizeRootObjectToView);
widget2->setSource(QUrl("qrc:/subwindow1.qml"));
widget2->show();
Subwindow1->setWidget(widget2);
Subwindow1->resize(700,640);
Subwindow1->setWindowTitle("Subwindow 1");
Subwindow1->setAttribute(Qt::WA_DeleteOnClose,false);
Subwindow1->setWindowFlag(Qt::FramelessWindowHint);
Subwindow1->addSubWindow(Subwindow1);
mdiArea->setActiveSubWindow(Subwindow1);
Subwindow1->show();
Subwindow2 = new QMdiSubWindow(mdiArea);
QQuickWidget* widget3 = new QQuickWidget(Camera1);
widget3->setResizeMode(QQuickWidget::SizeRootObjectToView);
widget3->setSource(QUrl("qrc:/subwindow2.qml"));
widget3->show();
Subwindow2->setWidget(widget3);
Subwindow2->resize(304,270);
Subwindow2->setWindowTitle("Subwindow 2");
Subwindow2->setAttribute(Qt::WA_DeleteOnClose,false);
Subwindow2->setWindowFlag(Qt::FramelessWindowHint);
mdiArea->addSubWindow(Subwindow2);
mdiArea->setActiveSubWindow(Subwindow2);
Subwindow2->show();
Subwindow3 = new QMdiSubWindow(mdiArea);
QQuickWidget* widget4 = new QQuickWidget(Camera2);
widget4->setResizeMode(QQuickWidget::SizeRootObjectToView);
widget4->setSource(QUrl("qrc:/subwindow3.qml"));
widget4->show();
Subwindow3->setWidget(widget4);
Subwindow3->resize(304,270);
Subwindow3->setWindowTitle("Subwindow 3");
Subwindow3->setAttribute(Qt::WA_DeleteOnClose,false);
Subwindow3->setWindowFlag(Qt::FramelessWindowHint);
mdiArea->addSubWindow(Subwindow3);
mdiArea->setActiveSubWindow(Subwindow3);
Subwindow3->show();

For example :
You have Subwindow1 with (700,640)
The code is : Subwindow1->setFixedSize(new QSize(700,640))
Hope it help !
https://doc.qt.io/qt-5/qwidget.html#setFixedSize

Related

QScrollArea with a QWidget in a QSplitter

I´m making a project for my class, and I need to put a scrollArea in a widget (I choosed a splitter) and I want to push a button and create more scrollArea inside this widget. This is what I´ve done:
I create the button like this:
self.AddCanal = QAction(QIcon(), "Add channel", self, shortcut = "Shift+Ctrl+c", triggered = self.addChannel)
And I put it in a QToolBar().
Then, I create the scrollArea. I put the scrollArea with the Qwidget (in this case I use a QwtPlot) in a QSplitter (splitter1), and then I put a frame and the splitter in another splitter (splitter2). And at last, I put splitter2 and another frame in one last splitter (splitter3). You can see it here:
self.scrollLayout = QFormLayout()
self.canal = QwtPlot()
self.canal.setLayout(self.scrollLayout)
self.scrollArea = QScrollArea()
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.canal)
self.scrollArea = QScrollArea()
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.canal)
splitter2 = QSplitter(Qt.Horizontal)
splitter2.addWidget(self.frame)
splitter2.addWidget(splitter1)
splitter3 = QSplitter(Qt.Vertical)
splitter3.addWidget(splitter2)
splitter3.addWidget(self.frame_3)
I made it like this, because in one frame I will put a tree widget, and in the bottom frame i will put a QtextEdit().
Well, now I need that the button, when click it, creates another scrollArea in the splitter1. And I want to create at minimum 5 extra scrollAreas.
How can I accomplish this?
I solve it creating a method like this:
def addChannel(self):
global channelCount
self.scrollLayout = QFormLayout()
self.canal = QwtPlot()
self.canal.setLayout(self.scrollLayout)
self.scrollArea = QScrollArea()
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.canal)
if channelCount <= 5:
self.splitter1.addWidget(self.scrollArea)
channelCount += 1
return channelCount
using "channelCount" as a global variable starting it in 1, just because i only want 5.
And i add:
self.addchannel()
at the QMainWindow class
Hope it can help somebody.

The inferior stopped because it received signal from the Operating System error on resizable scrollarea

I have a QScrollArea inside QTabWidget and I have a QWidget beside my QTabWidget. I want QScrollArea to be resized when my main window is resized, so I have made this code like this:
void frmSummaryContact::on_btnAddNewContact_clicked()
{
MainWindow *mnWindow = qobject_cast<MainWindow *>(this->parent()->parent()->parent()->parent()->parent()->parent());
QTabWidget *tbWidget = qobject_cast<QTabWidget *>(this->parent()->parent()->parent()->parent());
frmDetailContact *frm = new frmDetailContact(mnWindow, "input", -1, mnWindow->rightPane());
QScrollArea *scrlForm = new QScrollArea;
scrlForm->setWidgetResizable(true);
scrlForm->setWidget(frm);
mnWindow->AddNewTab(tbWidget, scrlForm, "Add Contact");
}
my QTabWidget is in different form, so I cast it with qobject_cast. Meanwhile in another form, I have a toogle button to hide QWidget so my QTabWidget get wider. So in that form I have a code like this:
void frmDetailContactToggle::on_btnSearch_clicked()
{
MainWindow *mnWindow = qobject_cast<MainWindow *>(this->parent()->parent()->parent());
QLayoutItem *child;
while ((child = mnWindow->rightPane()->layout()->takeAt(0)) != 0)
child->widget()->setVisible(false);
mnWindow->rightPane()->setVisible(false);
QScrollArea *scrlContent = qobject_cast<QScrollArea *>(mnWindow->tabContentWidget()->currentWidget());
scrlContent->setWidgetResizable(false);
mnWindow->tabContentWidget()->setGeometry(mnWindow->tabContentWidget()->x(), mnWindow->tabContentWidget()->y(), m_width - mnWindow->tabContentWidget()->x() - 10, mnWindow->tabContentWidget()->height());
scrlContent->setWidgetResizable(true);
m_showRightPane = false;
}
I have realized that I can't change the geometry when WidgetResizable is true. It showed "The inferior stopped because it received signal from the Operating System" error. So I thought about making it false, changing the geometry, and making it true again. But when I want to make it true, I encounter the same error. Could anyone please help me to solve my problem?
if your program used uninitialized pointers,that may causes SIGSEGV.

Qt 4.7.4 QPropertyAnimation not working

I'm trying to have animation on a button click event. But somehow the animation is not working. I have referred the Qt reference docs, but could not find the root cause which is causing the issue
Below is sample code :
void MainWindow::AnimationClick()
{
// define toolbar y movement positions for animation
TOOLBAR_Y_SHOWN = 0;
TOOLBAR_Y_HIDDEN = -m_AnimatedWidget->height();
m_AnimatedWidget = new AnimatedWidget(this);
QPropertyAnimation *m_ani = new QPropertyAnimation(m_AnimatedWidget, "pos", this);
m_ani->setDuration(500);
m_ani->setEndValue(QPoint(m_AnimatedWidget->pos().x(), TOOLBAR_Y_HIDDEN));
m_ani->setEasingCurve(QEasingCurve::InBack);
m_ani->start();
}
With the above implementation nothing is happening on the click event.
Any suggestions , Thanks.
This looks wrong:
TOOLBAR_Y_HIDDEN = -m_AnimatedWidget->height();
m_AnimatedWidget = new AnimatedWidget(this);
First you access m_AnimatedWidget then you allocate it?
When you get a crash, such as segmentation fault, always run your program in a debugger. It would have helped you find this error quite easy as it would have stopped on the line of the error.
m_ani->setDuration(500);
setDuration() argument is expressed in milliseconds. You should probably put more than half a second when you are testing.
I got it. I was not allowing the m_AnimatedWidget to show upon the screen.
Below is the edited snippet.
void MainWindow::AnimationClick()
{
// define toolbar y movement positions for animation
TOOLBAR_Y_SHOWN = 0;
m_AnimatedWidget = new AnimatedWidget(this);
TOOLBAR_Y_HIDDEN = -m_AnimatedWidget->height();
QPropertyAnimation *m_ani = new QPropertyAnimation(m_AnimatedWidget, "pos", this);
m_ani->setDuration(5000);
m_ani->setEndValue(QPoint(m_AnimatedWidget->pos().x(), TOOLBAR_Y_HIDDEN));
m_ani->setEasingCurve(QEasingCurve::InBack);
m_ani->start();
m_AnimatedWidget->show();
}

How to make a QMdiArea subwindow widget non-resizeable?

So the non-QMdiArea version of my code,
MyWidget::MyWidget(QWidget* parent)
{
...
layout()->setSizeConstraint( QLayout::SetFixedSize );
}
MainWindow::MainWindow(...)
{
...
MyWidget* wgt = new MyWidget(NULL);
wgt->show();
}
works just fine and produces a widget that the user can't resize. But when the MainWindow code is replaced with
MainWindow::MainWindow(...)
{
...
MyWidget* wgt = new MyWidget(ui->mdiArea); //Or MyWidget(NULL), same result
ui->mdiArea->addSubWindow(wgt);
}
the window, now within the QMdiArea, is resizeable. It doesn't seem to be an issue of Qt::WindowFlags, they don't handle resize policy. Surely there is a way to do this? NB I cant use something like setFixedSize(ht, wd) since the size of the widget can change programmatically (subwidgets are added and removed). But the user should not be able to resize it.
Even though MyWidget is not resizeable, when you call:
ui->mdiArea->addSubWindow(wgt);
The widget is put in a QMdiSubWindow which is resizeable. All you have to do is get the window that's created and fix its size:
QMdiSubWindow* subWindow = ui->mdiArea->addSubWindow(wgt);
subWindow->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
This should work, but I haven't tried this code myself.
EDIT: well... apparently that doesn't fix the size. :(
The following worked for me:
MyWidget* wgt = new MyWidget(ui->mdiArea);
QMdiSubWindow* subWindow = ui->mdiArea->addSubWindow(wgt);
subWindow->setFixedSize(wgt->size());
wgt->show();

How to create domodal dialog box in mfc dynamically?

i have created two dailog box statically.
CParentDailog
CMyDailog
and then
CParentDailog
{
CMyDailog *l_pdailog;
}
in oninitdailog of CParentDailog ia mdoing
l_pdailog = new CMyDailog();
l_pdailog ->create(ID_DAILG1); // this is id of CMyDailog
l_pdailog ->Domodal(); // crashing at this point
why it is crashing?
Hi you need to set parent window:
l_pdailog = new CMyDailog(pWndparent);
l_pdailog ->Domodal();