QMainWindow focus bzw. in den Vordergrund bringen.

Alles rund um die Programmierung mit Qt
Antworten
qt-oli
Beiträge: 2
Registriert: 5. März 2009 12:58

QMainWindow focus bzw. in den Vordergrund bringen.

Beitrag 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!!!!!!
qt-oli
Beiträge: 2
Registriert: 5. März 2009 12:58

Beitrag 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();
AuE
Beiträge: 918
Registriert: 5. August 2008 10:58

Beitrag 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();
	}
}
Antworten