Seite 1 von 1

QMainWindow focus bzw. in den Vordergrund bringen.

Verfasst: 5. März 2009 13:16
von qt-oli
Hi Leute,

ich habe folgendes Problem, wie kann ich in QT 4.2 mein QMainWindow nach einem DBus Methoden Aufruf in den Vordergrund bringen.

Zum Beispiel wenn ich auf der Konsole ein dbus-send mache...!

In meiner QMainWindow Slot Methode mach ich

Code: Alles auswählen

QApplication::setActiveWindow(this);
this>activateWindow();
this->raise();
Leider funktioniert das nicht. Es kommt einfach nicht in den Vordergrund.
Habt Ihr eine Idee?
Danke im Vorraus!!!!!!

Verfasst: 5. März 2009 20:10
von qt-oli
...ok, so klappt's, aber scheint mir doch irgendwie ganz schön dirty...

Code: Alles auswählen

setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
setFocus();
setWindowState(this->windowState() | Qt::WindowActive);
QApplication::setActiveWindow(this);
activateWindow();
setWindowState(Qt::WindowActive);
raise();
setWindowFlags(Qt::Window);
show();

Verfasst: 6. März 2009 10:29
von AuE
alsoo dein Code is.... ja ... ehm dirty. ;-)

anbei en kleines Bsp für fullscreen(AlwaysOnTop) und minSize wechsel

Code: Alles auswählen

void Klasse::on_cbImmerImVordergrund_stateChanged(int iValue)
{
	
	QPoint position = pos();
							
	int flagsasint = static_cast<int>(windowFlags());

	if ( iValue > 0) // always on top
	{
		bit_support::bit_state(flagsasint, ONTOPBIT, bit_support::eset);
		this->setWindowFlags((Qt::WindowFlags)flagsasint);
		this->showFullScreen();
	}
	else
	{	
		bit_support::bit_state(flagsasint, ONTOPBIT, bit_support::eunset);

		this->setGeometry(0,0, this->minimumWidth(), this->minimumHeight());
		position.setY(position.y() + 10);
		this->move(position);
	
		this->setWindowFlags((Qt::WindowFlags)flagsasint);
		this->show();
	}
}