Launching new form by a button click in qt gui application? - qt

I am trying upon some simple applications. I would like to know how to launch a new form by clicking a button from main window. Please explain this to me with a simple example.

QT already comes with a simple example on how to create and show different types of windows and dialogs. Take a look here: Window Flags Example
Also if you already have a main widow in your application, you can take a look how it's shown (main function in your main.cpp) for your project and use the same technique:
MainWindowTest *testWindow = new MainWindowTest();
testWindow->show();
If you need to show a modal dialog, use your dialog's exec() method:
Dialog *dialog = new Dialog();
dialog->exec();
hope this helps, regards

Related

error dialog box with Qt quick

i'm programming a Qt Quick application and I'm looking for a possibility to display the user errors. In Qt widgets there is QMessageBox but i can not find any equivalent to this in Qt Quick.
Sure i can create a MessageBox by myself but I can't imagine that there is no given possibility?
I found an ebook on the official site here and there is an Dialog described on page 67 but it doesn't work anymore and i can't find any further information about that. Is it dropped in the current version?
Thanks in advance
There is no Qt-Quick component for this yet. What I do in my application is using the Window QML component. I set the modality property to Qt.WindowModal to have it as a modal Window. You can then use the Button component to create OK/Cancel buttons.
Another thing I do is create these modals dynamically when something wrong occurs using Qt.createComponent() in QML.
Edit: Just discovered a new Dialog component that will be released in Qt5.2 that seems to match what you are looking for: MessageDialog

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);

Qt creator Screen navigation

I am doing screen navigation in my application for example i am moving firstwindow.cpp to secondwindow.cpp. I used below code to navigate above function but my problem is that i successfully able to see second window but at the same time my first window left opened so how do i close first or previous window.
r1 = new secondform(this);
r1->showFullScreen();
You can use the hide() function in order to hide a widget/window.
You should consider using QWizard for navigating through widgets instead of implementing the functionality yourself.

how to se t the right click operations of a link in qtwebkit

How to edit QtWebKit's right-click context menu in Qt Creator?
how to get response in QtWebKit
https://qt-project.org/forums/viewthread/15149/
i have seen all these threads and more but cant get my anwser
i want to set the righ click menu of links images frames etc. in qtwebkit
in qwebview
i have heard that we have to install an event filter and get the object which is at that position but i am not geting it
can you tell me a simple and sweet solution
tell how to set the operation of that action
also iut would be great if you can give a sample live working code
i have heard that we have to use QMenu and QAction for this.
To get a "standard" menu from QWebView based upon where you clicked, do:
page()->updatePositionDependentActions(pos);
QMenu* ctxMenu = page()->createStandardContextMenu();
to know on what you clicked, use
QWebHitTestResult hit = page()->mainFrame()->hitTestContent(pressPoint.toPoint());

Another Window over QMainWindow in 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.

Resources