View Full Version : Qt::Tool
JeanC
5th February 2008, 18:10
As soon as I setWindowFlags(Qt::Tool) strange things start happening. :)
The window does not get keyboard focus on startup.
When closing with the X in the upper right corder, the process is not terminated (but it does when called via slot aApp quit().
Also closeEvent(QCloseEvent *event) does not get called.
It does this with an otherwise empty test project.
There's a Qt example program windowflags, but this one gets terminated when choosing a Tool window.
What could this be?
P.s. I'm using qdevelop, great tool, and the project is in debug mode.
[edit] I think a window with Qt::Tool flag cannot be a normal mainwindow. It is a qwidget in the windowflags example, not a qmainwindow.
jpn
6th February 2008, 08:28
Could you provide a minimal compilable example we could try ourselves?
luf
6th February 2008, 14:18
When reading your post, it looks like you are trying to put a QT::tool flag on a widget inside a QMainWindow.
If that is the case, it is correct that strange things will happen, as it tries making a tool window out of your widget inside a QMainWindow. Try using the QT::tool flag on either a dialog or the mainwindow directly if you are trying to have a tooltip-like-window
JeanC
7th February 2008, 15:56
@jpn
Sorry I hadn't noticed your question untill now.
#include <QApplication>
#include "mainwindowimpl.h"
//
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
MainWindowImpl win;
win.show();
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
#include "mainwindowimpl.h"
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
setWindowFlags(Qt::Tool);
}
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include <QMainWindow>
#include "ui_mainwindow.h"
//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
private slots:
};
#endif
@luf
Well no, it's on a main window as you can see.
The example 'windowsflags' uses a widget to set Qt::Tool and is working,
jpn
7th February 2008, 20:54
Alright, I found the reason. QWidget::create() clears the Qt::WA_QuitOnClose attribute for anything but Qt::Window, Qt::Widget or Qt::Dialog. The workaround is to call for example QWidget::show() first, and set the attribute by hand afterwards:
#include <QtGui>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QMainWindow win(0, Qt::Tool);
win.show(); // must be called before setting Qt::WA_QuitOnClose
win.setAttribute(Qt::WA_QuitOnClose);
return app.exec();
}
JeanC
8th February 2008, 10:18
Thanks jpn,
There is another issue. That window does not get focus at startup. Calling setFocus() in main or in the constructor does not help.
jpn
8th February 2008, 10:35
Looks like you have to explicitly activate the window:
win.activateWindow();
JeanC
8th February 2008, 15:58
Grr, that won't set focus jpn. Neither in main nor constructor.
:)
Looks like you have to explicitly activate the window:
win.activateWindow();
jpn
9th February 2008, 10:56
Alright, this seems to be something WM specific then. While it worked on Windows the window stays inactive on X11. Try this:
// main.cpp
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0)
: QMainWindow(parent, flags)
{
setCentralWidget(new QTextEdit(this));
}
public slots:
void activateWindow()
{
QMainWindow::activateWindow();
}
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
MainWindow win(0, Qt::Tool);
win.show(); // must be called before setting Qt::WA_QuitOnClose
win.setAttribute(Qt::WA_QuitOnClose);
QTimer::singleShot(0, &win, SLOT(activateWindow()));
return app.exec();
}
#include "main.moc"
PS. Could you update your profile to indicate used platforms, please?
JeanC
9th February 2008, 12:59
Works! Thanks.
Alright, this seems to be something WM specific then. While it worked on Windows the window stays inactive on X11. Try this:
Done. Only ubuntu so far, on win I used c++ builder.
PS. Could you update your profile to indicate used platforms, please?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.