How can I prevent a QApplication with a QMainWindow from stealing the keyboard focus when it starts? I'd like it to become active only after clicking on or alt-tabbing to it.
You could use showMinimized() instead of show() for you main window.
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow w;
w.showMinimized();
return app.exec();
}
Related
Hey so I need to export a qt application as a .dll and , so I dont want any arguments like argc and argv , but QApplication needs them , so i tried this
int main()
{
int c=1;
char** v = (char**)("ApplicationName");
QApplication app(c,v);
MainWindow window;
window.show();
return app.exec();
}
but I get segfault from QtCore... Can someone help me bypass the segfault and create the QApplication without needing argc and argv?
This didnt solve the problem cause it needs argv defined ...
QApplication app(argc, argv)
Try this:
int main()
{
char* args[] = { (char*)"AppName" };
QApplication app(1,args);
MainWindow window;
window.show();
return app.exec();
}
Referring to this question.
After embedding an external application with the code:
#include <QApplication>
#include<QProcess>
#include<QDesktopServices>
#include<QUrl>
#include<QWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow *w = new QMainWindow();
w->setWindowTitle("Genome Embedded Calculator");
QWindow* window = QWindow::fromWinId(41943047); // Hardcoded Window Id for Genome Calculator
window->setFlags(Qt::FramelessWindowHint);
QWidget *widget = QWidget::createWindowContainer(window);
w->setCentralWidget(widget);
w->show();
return a.exec();
}
How to detach the QWindow after closing the application?
I want the gnome-calculator process to continue working after closing my application.
I am trying to hide the MainWindow of my Qt desktop app during startup, and to show a splashscreen. Both only happens after the loading phase, even though I call both splash.show() and window.hide() before the loading phase. I tried to split loading phase and constructor, but result is the same. How can I achieve both before the loading phase ?
Update 1
To display the splash screen, I had to add a call to QApplication::processEvents()
Update 2
The black window was actually not the MainWindow, but a ghost window that popped because scrollArea->setVisible(true) was called in the constructor.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmap(QStringLiteral(":/ressources/icons/icon.png"));
QSplashScreen splash(pixmap);
splash.show();
MainWindow window; // this loads for 5-6 seconds
a.processEvents();
window.showLoginPrompt();
splash.finish(&window);
return a.exec();
}
Based on your code and some example I could make it run like you are trying to do.
You only need to call your promptLogin function instead.
#include <QApplication>
#include <QTimer>
#include <QSplashScreen>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSplashScreen *splash = new QSplashScreen;
splash->setPixmap(QPixmap("D:\\Projects\\SplashScreen\\TestSplashScreen\\splash.png"));
splash->show();
MainWindow mainWin;
QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2500, &mainWin, SLOT(show()));
return app.exec();
}
Why when I run code bellow, I don't have close button, like on this screenshot?
There is also no close button with other flags, like Qt::WindowMinimizeButtonHint or Qt::WindowMinMaxButtonsHint and other.
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget wgt;
wgt.setWindowFlags(Qt::Window | Qt::WindowMaximizeButtonHint);
wgt.show();
return a.exec();
}
Close button is available with wgt.setWindowFlag(Qt::Window). Even without wgt.setWindowFlag() is still available. But as soon as I add second flag like Qt::WindowMaximizeButtonHint or any other, with button, that must become unavailable, close button become unclickable too.
Try this:
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget wgt;
wgt.setWindowFlags(Qt::Window | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
wgt.show();
return a.exec();
}
More info:
A window flag is either a type or a hint. A type is used to specify various window-system properties for the widget.
Window Flags Example
I want to know how to set window title in Qt in maximized mode.
window->setWindowtitle("window");
But this does not work in maximized mode.
playback_main *pbw = new playback_main;
pbw->setWindowTitle("PlayBack");
pbw->showMaximized();
This is not working.
Your code works for me on a QMainWindow in, admittedly, qt 4.7. Do you need to force an update with either of:
pbw->update();
qApp->processEvents();
is pbw a QMainWindow or just a widget?
I've tried the following code on linux which works too:
#include <QApplication>
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.setWindowTitle("testing");
w.showMaximized();
return a.exec();
}