Seite 1 von 1

Menubar funktioniert nicht mehr

Verfasst: 16. November 2009 22:24
von krone
Hallo zusammen,

hab ein Problem und zwar habe ich mit dem QT-Designer eine GUI erstellt. Dazu eine Menubar. Hat alles wunderbar funktioniert.

Dann habe ich zusätzlich noch die Funktionen für ein SystemTray erstellt und wenn ich jetzt das Programm ausführe, kann ich die MenuBar nicht mehr anklicken. Also es öffnet sich kein Untermenü und der Hauptmenüpunkt in der Leiste wird auch nicht hinterlegt.
Woran kann das liegen?

Gibt es ein Problem mit der MenuBar und show()/hide() oder setVisible() ?

Danke schonmal

Verfasst: 22. November 2009 18:13
von krone
Hat denn niemand eine Idee?

Verfasst: 22. November 2009 18:46
von upsala
Och, Ideen haben wir viele. Die Frage ist, ob sie zu deinem Code passen...

Verfasst: 22. November 2009 22:29
von krone
Naja jede Idee kann mir helfen.
Also wenn ich das SystemTrayIcon rausnehme, dann funktioniert alles.
Meine SystemTray-Klasse sieht folgendermaßen aus:

Code: Alles auswählen


package Notification;

import com.trolltech.qt.QSysInfo;
import com.trolltech.qt.core.QCoreApplication;
import com.trolltech.qt.gui.*;


public class ClientSystemTray extends QWidget{
	
	private QSystemTrayIcon trayIcon;
    private QMenu trayIconMenu;

    private QAction toggleVisibilityAction;


    public ClientSystemTray() {
        this(null);
    }

    public ClientSystemTray(QWidget parent) {
        super(parent);
        if (!QSystemTrayIcon.isSystemTrayAvailable())
            QMessageBox.warning(this, tr("System tray is unavailable"),
                                      tr("System tray unavailable"));

        // Create the menu that will be used for the context menu
        trayIconMenu = new QMenu(this);
        trayIconMenu.aboutToShow.connect(this, "updateMenu()");
        toggleVisibilityAction = new QAction("Show/Hide", this);
        toggleVisibilityAction.triggered.connect(this, "toggleVisibility()");
        trayIconMenu.addAction(toggleVisibilityAction);

        QAction restoreAction = new QAction("Restore", this);
        restoreAction.triggered.connect(this, "showNormalSize()");
        trayIconMenu.addAction(restoreAction);

        QAction minimizeAction = new QAction("Minimize", this);
        minimizeAction.triggered.connect(this, "showMinimizedSize()");
        trayIconMenu.addAction(minimizeAction);

        QAction maximizeAction = new QAction("Maximize", this);
        maximizeAction.triggered.connect(this, "showMaximizedSize()");
        trayIconMenu.addAction(maximizeAction);

        trayIconMenu.addSeparator();

        QAction quitAction = new QAction("&Quit", this);
        quitAction.triggered.connect(this, "exitProgram()");
        trayIconMenu.addAction(quitAction);

        // Create the tray icon
        trayIcon = new QSystemTrayIcon(this);
        trayIcon.setToolTip("MakeMyLunch");
        trayIcon.setContextMenu(trayIconMenu);
        trayIcon.setIcon(new QIcon(new QPixmap("classpath:Icons/tray.png")));

        trayIcon.messageClicked.connect(this, "balloonClicked()");

        trayIcon.show();      
        
    }
    
    public void exitProgram(){
    	QCoreApplication.exit(0);
    }

    protected void updateMenu() {
        toggleVisibilityAction.setText(this.parentWidget().isVisible() ? tr("Hide") : tr("Show"));
    }

    protected void toggleVisibility() {    	
        if (this.parentWidget().isVisible())
            this.parentWidget().hide();
        else
        	this.parentWidget().show();
    }

    protected void showMessage() {
        // #ifdef Q_WS_MAC
        if (QSysInfo.macVersion() != 0) {
            QMessageBox.information(this, tr("System tray example"),
                    tr("Balloon tips are not supported on Mac OS X"));
        } else {
           
        }
    }
    
    protected void balloonClicked() {
        System.out.println("BALLOON CLICKED");
    }
    
    public void showNormalSize(){
    	trayIcon.showMessage("Information", "This is an information");
    	this.parentWidget().showNormal();
    }
    
    public void showMinimizedSize(){
    	this.parentWidget().showMinimized();
    }
    
    public void showMaximizedSize(){
    	this.parentWidget().showMaximized();
    }
}



Ich bin für jeden Tipp dankbar.