Another Window over QMainWindow in Qt - qt

Can i have another window over main window in Qt , and how can i implement it? I have a plugin which must return another window. I created in plugin a QWidget and set it as centralWidget but my app crashes.Anyway this will not show two windows at same time . Could someone explain how to do that ?

Any new widget created without a parent will show up as a new window. Don't try to reset 'centralWidget' unless you don't actually want the old one anymore.
If all you want is a main window whose contents change, take a look at StackedWidget.

Related

How to enable the menubar in a QUndoView window in Qt?

I use a QUndoStack and I want to show its content using a QUndoView. I create the view as follows:
undoView = new QUndoView(&_undoStack);
undoView->setWindowTitle(tr("Undo Stack"));
undoView->show();
The view is created in a separate window (which is what I want), but that window has a disabled menu bar, so I cannot move it at all, or close it. Is there a way to enable it?
Ok so the issue was that the main window had a window modality of Qt::WindowModality::ApplicationModal which blocks all input to any other top-level window. Simply changing the main window to non-modal with SetWindowModality fixed this.
hide();
setWindowModality(Qt::WindowModality::NonModal);
show();
Alternatively change the modality directly in Qt creator if the main window was created from there.

qt qwidgets that I create programmatically (such as Labels) never show, but ones that I create with the IDE work fine. I'm new to qt

I'm new to QT. when I create a qwidget such as a qlabel, programmatically, it never shows in my main window or anywhere else. But when I create one using the IDE it works fine. What am I missing ?
By default, widgets are set to invisible, therefore, you need to call .show() to make a widget visible. For example,
QLabel *label = new QLabel("click");
label->show();
Using the debugger I noticed that my QLabel had the wrong parent. Setting the parent correctly cured all of my problems. The other answers to my question were relevant too.

How to start second QDialog window on side of MainWindow?

I have a application in Qt, and a MainWindow. Now, I also added a helping QDialog which can be hooked up. This QDialog does not influence the programmflow, it just displays information.
But, it always starts on top of the MainWindow :/
SO I would like to start it on the side of the main window, so that it does not hinder the view to the main window?? How?
In my opinion , You should try this,
Use the overload of the QWidget::setParent() function to change the ownership of a QDialog widget, using set as NULL(but It will not share the parent's taskbar entry).
QDialog::show() returns control to the caller immediately, So it will not interfere in mainwindow flow.
Let's say, your application is in the full screen mode. Where then the QDialog should appear? It will be shown on the top and you won't be satisfied again.
If it doesn't influence the flow of the app then you are using it to communicate some sort of message. Can you use different ways? For instance, QStatusBar?
If not, why not to split the mainWindow with QSplitter or similar classes and provide an area where you can post all the info messages?
It sounds you want modaless dialog. In main window, use a slot to create the dialog.
void MainWindow::show_dialog()
{
if ( pDialog== NULL )
pDialog= new XYZ_Dialog(this);
QPoint p = pos();
QSize s = frameSize();
pDialog->setGeometry(p.x()+s.width(), p.y(), s.width()*1/2, s.height());
pDialog->show();
}
What I try to say is if the position of the new dialog bothers you, you set the position and size of it, before showing it.

Destroy QWidget returned from Plugin in Qt

My app loads a plugin which creates a window (QWidget), but I can not destroy it when I exit from QMainWindow, obviously because widget returned from plugin is not a child of QMainWindow. The issue is that if I make that window to be a child of mainwindow, I get a window on another window. But I need them both to be separated. I did them separated (but main window has no control over window from plugin), in my case I do not know how to close window from plugin when app quits. How can I achieve that?
Just delete it. If you don't assign it a parent, no other widget has ownership. So you should simply be able to destroy it yourself on exit.

Qt negative button not working

In my Qt symbian app, I have over ride the negative exit button with back to come back on main screen and then again over ride it with exit to close the app, my app is working fine on emulator but when I test it on device it shows exit button instead of back, some time it shows back also but if I go to the same page twice then again it start showing exit button, frustrating part is that app is working fine on Qt emulator but not on device. Does somebody knows whats the problem is. I am using
back->setSoftKeyRole(QAction::NegativeSoftKey);
this->addAction(back);
to over ride the exit button before loading the screen and
back->setSoftKeyRole(QAction::NegativeSoftKey);
this->removeAction(back);
to removing back button when coming back to mainWindow.
Create vertical layout and Widget which You will add on scrollarea with parent as that class this e.g
QVBoxLayout *vlay = new QVBoxLayout(this);
QWidget *area = new QWidget(this)
And add widget to it
This will make it child of parent class.
works fine for me.
I think adding and removing QAction objects here and there is asking for problems.
You should try to redesign your application to use a QStateMachine to handle transitions between states.
Take a look at the introductory documentation here.
Refer this LINK for custom softkeys..
QAction* myAction= new QAction(tr("My Action"), this);
myAction->setSoftKeyRole(QAction::NegativeSoftKey);
addAction(myAction);

Resources