[gelöst]context menu geht bei mir nicht.

Alles rund um die Programmierung mit Qt
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

[gelöst]context menu geht bei mir nicht.

Beitrag von defenderLQ »

hi

also ich konnte schon lang nicht mein problem mit dme context menue nicht lösen trotz paar hilfen hier im forum,
vielleicht sieht jemand der sich damit auskennt meine fehler.

DownloadsDialog.cpp:

Code: Alles auswählen

#include "rshare.h"
#include "DownloadsDialog.h"
#include "downinfo/DownInfoWindow.h"
#include <QHeaderView>

#include <QContextMenuEvent>
#include <QMenu>
#include <QCursor>

/* Images for context menu icons */
#define IMAGE_INFO       ":/images/informations_16x16.png"

/** Constructor */
DownloadsDialog::DownloadsDialog(QWidget *parent)
: MainPage(parent)
{
  /* Invoke the Qt Designer generated object setup routine */
  ui.setupUi(this);


  /* Hide platform specific features */
#ifdef Q_WS_WIN

#endif
}


void DownloadsDialog::contextMenuEvent(QContextMenuEvent *e)
{
	//QMenu popMenu(this);
	popMenu = new QMenu(this);  
	
	//popMenu.addAction(_showdowninfoAct);
	//popMenu.addSeparator();
	//popMenu.addAction(_resumeAct);
	//popMenu.exec(e->globalPos());
	
	popMenu->addAction(_showdowninfoAct);
	popMenu->addSeparator();
	//popMenu->addAction(_resumeAct);
	popMenu->exec(e->globalPos());
} 

void DownloadsDialog::createActions()
{

  _showdowninfoAct = new QAction(QIcon(IMAGE_INFO), tr("Show Informations"), this);
  connect(_showdowninfoAct, SIGNAL(triggered()), this, SLOT(showDownInfoWindow()));
  
//  _resumeAct = new QAction(QIcon(), tr("Resume"), this);
//  connect(_resumeAct, SIGNAL(triggered()), this, SLOT(close()));

}

/** Shows Downloads Informations */
void DownloadsDialog::showDownInfoWindow()
{
    DownInfoWindow *downinfoWindow = new DownInfoWindow();
    downinfoWindow->show();
}
DownloadsDialog.h:

Code: Alles auswählen

#ifndef _DOWNLOADSDIALOG_H
#define _DOWNLOADSDIALOG_H

#include <QFileDialog>

#include <config/rsharesettings.h>

#include "mainpage.h"
#include "ui_DownloadsDialog.h"



class DownloadsDialog : public MainPage 
{
  Q_OBJECT

public:
  /** Default Constructor */
  DownloadsDialog(QWidget *parent = 0);
  /** Default Destructor */


  
 

private slots:

  void showDownInfoWindow();
  
private:
  /** Create the actions on the tray menu or menubar */
  void createActions();
  /** Create the context popup menu and it's submenus */
  void contextMenuEvent( QContextMenuEvent *e);

  /** Define the popup menus for the Context menu */
  QMenu* popMenu;
  /** Defines the actions for the context menu */
  QAction* _showdowninfoAct;
  QAction* _resumeAct;

  /** Adds a new action to the toolbar. */
  void addAction(QAction *action, const char *slot = 0);

  /** Qt Designer generated object */
  Ui::DownloadsDialog ui;
};

#endif



also habe die policy zum context menue schon alle probiert ohne erfolg bis jetzt.
Zuletzt geändert von defenderLQ am 2. November 2006 23:44, insgesamt 1-mal geändert.
upsala
Beiträge: 3946
Registriert: 5. Februar 2006 20:52
Wohnort: Landshut
Kontaktdaten:

Beitrag von upsala »

Kommentiere mal folgende Zeile aus:

Code: Alles auswählen

ui.setupUi(this); 
und probier dann mal dein Context-Menü nochmal aus...
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

nein geht auch nicht!

dann verschwindet mein QTreeWidget auch im downlaodsDialog mit den dazugehörigne items.

Bild

man sieht was das ziemlich klein ist und es steht kein "Show Informations"
im Context menu.

Bild

Code: Alles auswählen

#include "rshare.h"
#include "DownloadsDialog.h"
#include "downinfo/DownInfoWindow.h"
#include <QHeaderView>

#include <QContextMenuEvent>
#include <QMenu>
#include <QCursor>

/* Images for context menu icons */
#define IMAGE_INFO       ":/images/informations_16x16.png"

/** Constructor */
DownloadsDialog::DownloadsDialog(QWidget *parent)
: MainPage(parent)
{
  /* Invoke the Qt Designer generated object setup routine */
  ui.setupUi(this);


  /* Hide platform specific features */
#ifdef Q_WS_WIN

#endif
}


void DownloadsDialog::contextMenuEvent(QContextMenuEvent *e)
{

	popMenu = new QMenu(this);  
	
	popMenu->addAction(_showdowninfoAct);
	popMenu->addSeparator();
	popMenu->exec(e->globalPos());
} 

void DownloadsDialog::createActions()
{

  _showdowninfoAct = new QAction(QIcon(IMAGE_INFO), tr("Show Informations"), this);
  connect(_showdowninfoAct, SIGNAL(triggered()), this, SLOT(showDownInfoWindow()));
  

}

/** Shows Downloads Informations */
void DownloadsDialog::showDownInfoWindow()
{
    DownInfoWindow *downinfoWindow = new DownInfoWindow();
    downinfoWindow->show();
}
ChMaster
Beiträge: 252
Registriert: 23. Februar 2005 14:44
Wohnort: RP -> Alzey
Kontaktdaten:

Beitrag von ChMaster »

servus,

hier ein richtiger codesnipe der dich weiter bringt: (hoffe ich :P)

Code: Alles auswählen

DownloadsDialog::DownloadsDialog(QWidget *parent)
: MainPage(parent)
{
  /* Invoke the Qt Designer generated object setup routine */
  ui.setupUi(this);

connect( DEIN_QTREEWIDGEWT, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( DEIN_QTREEWIDGET_POPUPMENU_REQUEST_FUNCTION( QPoint ) ) );
  /* Hide platform specific features */
#ifdef Q_WS_WIN

#endif
} 

Code: Alles auswählen

	void DownloadsDialog::DEIN_QTREEWIDGET_POPUPMENU_REQUEST_FUNCTION( QPoint point )
	{
		QMenu contextMnu( this );
		QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );

		showdowninfoAct = new QAction( tr( "WAS WEIS ICH :)" ), this );
		connect( showdowninfoAct , SIGNAL( triggered() ), this, SLOT( showDownInfoWindow() ) );
		
		contextMnu.clear();
		contextMnu.addAction( showdowninfoAct);
		contextMnu.exec( mevent->globalPos() );
	}
ChMaster
------------ Projekte------------
DBoxFE
DMS
First4 (Plugin-Develper)
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

hi

ja wie muss ich mein downtreeWidget da angeben?

Code: Alles auswählen

#include "rshare.h"
#include "DownloadsDialog.h"
#include "downinfo/DownInfoWindow.h"
#include <QHeaderView>

#include <QContextMenuEvent>
#include <QMenu>
#include <QCursor>
#include <QPoint>
#include <QMouseEvent>

/* Images for context menu icons */
#define IMAGE_INFO       ":/images/informations_16x16.png"

/** Constructor */
DownloadsDialog::DownloadsDialog(QWidget *parent)
: MainPage(parent)
{
  /* Invoke the Qt Designer generated object setup routine */
  ui.setupUi(this);


connect( downtreeWidget_QTREEWIDGET, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( downtreeWidget_QTREEWIDGET_POPUPMENU_REQUEST_FUNCTION( QPoint ) ) ); 

  /* Hide platform specific features */
#ifdef Q_WS_WIN

#endif
}


void DownloadsDialog::downtreeWidget_QTREEWIDGET_POPUPMENU_REQUEST_FUNCTION( QPoint point ) 
{

      QMenu contextMnu( this );
      QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );

      showdowninfoAct = new QAction( tr( "Show Informations" ), this );
      connect( showdowninfoAct , SIGNAL( triggered() ), this, SLOT( showDownInfoWindow() ) );
      
      contextMnu.clear();
      contextMnu.addAction( showdowninfoAct);
      contextMnu.exec( mevent->globalPos() ); 
} 

void DownloadsDialog::createActions()
{

  //showdowninfoAct = new QAction(QIcon(IMAGE_INFO), tr("Show Informations"), this);
  //connect(showdowninfoAct, SIGNAL(triggered()), this, SLOT(showDownInfoWindow()));
  

}

/** Shows Downloads Informations */
void DownloadsDialog::showDownInfoWindow()
{
    DownInfoWindow *downinfoWindow = new DownInfoWindow();
    downinfoWindow->show();
}


<widget class="QTreeWidget" name="downtreeWidget" >
Zuletzt geändert von defenderLQ am 2. November 2006 00:28, insgesamt 3-mal geändert.
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

ups habe was vergessen aus lauter eile:

Code: Alles auswählen

#ifndef _DOWNLOADSDIALOG_H
#define _DOWNLOADSDIALOG_H

#include <QFileDialog>

#include <config/rsharesettings.h>

#include "mainpage.h"
#include "ui_DownloadsDialog.h"



class DownloadsDialog : public MainPage 
{
  Q_OBJECT

public:
  /** Default Constructor */
  DownloadsDialog(QWidget *parent = 0);
  /** Default Destructor */

  
  
 

private slots:

  void showDownInfoWindow();
  
private:
  /** Create the actions on the tray menu or menubar */
  void createActions();
  /** Create the context popup menu and it's submenus */
  void downtreeWidget_QTREEWIDGET_POPUPMENU_REQUEST_FUNCTION( QPoint point );

  /** Define the popup menus for the Context menu */
  QMenu* contextMnu;
  /** Defines the actions for the context menu */
  QAction* showdowninfoAct;
  QAction* _resumeAct;
  
  QTreeWidget* downtreeWidget_QTREEWIDGET;

  /** Adds a new action to the toolbar. */
  void addAction(QAction *action, const char *slot = 0);

  /** Qt Designer generated object */
  Ui::DownloadsDialog ui;
};

#endif

nun wie muss ich downtreewidget einfach ins puplic rein in .h ?

nach erfolgreichem kompilieren gehts immer noch nicht.
upsala
Beiträge: 3946
Registriert: 5. Februar 2006 20:52
Wohnort: Landshut
Kontaktdaten:

Beitrag von upsala »

Pack doch einfach mal dein Projekt in eine Zip-Datei uns stell sie hier rein...
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

ja das mit dem context menu hab ich schon seit anfang meines projects nicht in griff.
also seit august versuche ich schon verschiedene methoden versucht.
Zuletzt geändert von defenderLQ am 4. November 2006 19:17, insgesamt 1-mal geändert.
ChMaster
Beiträge: 252
Registriert: 23. Februar 2005 14:44
Wohnort: RP -> Alzey
Kontaktdaten:

Beitrag von ChMaster »

past, habe den xaceplus extractor ;)
ich schau es mir jetzt mal an und gebe dir dann die geänderten dateien
zurück.
Zuletzt geändert von ChMaster am 2. November 2006 22:57, insgesamt 1-mal geändert.
ChMaster
------------ Projekte------------
DBoxFE
DMS
First4 (Plugin-Develper)
-Marco-
Beiträge: 47
Registriert: 4. April 2006 16:35

Beitrag von -Marco- »

defenderLQ hat geschrieben:ja das mit dem context menu hab ich schon seit anfang meines projects nicht in griff.
hast du in deinen Projekt auch

Code: Alles auswählen

void contextMenuEvent( QContextMenuEvent *e);
virtual deklariert?
In den geposteten Sachen kann ich das nicht finden.
Gruß Marco
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

also ich hab das schon rausgschmissen weil es nicht ging und hier jemand mir anders vorgeschlagen hat.

mein sources mit contextmenuevent:
Downloadsdialog.cpp:

Code: Alles auswählen

#include "rshare.h"
#include "DownloadsDialog.h"
#include "downinfo/DownInfoWindow.h"
#include <QHeaderView>

#include <QContextMenuEvent>
#include <QMenu>
#include <QCursor>

/* Images for context menu icons */
#define IMAGE_INFO       ":/images/informations_16x16.png"

/** Constructor */
DownloadsDialog::DownloadsDialog(QWidget *parent)
: MainPage(parent)
{
  /* Invoke the Qt Designer generated object setup routine */
  ui.setupUi(this);


  /* Hide platform specific features */
#ifdef Q_WS_WIN

#endif
}


void DownloadsDialog::contextMenuEvent(QContextMenuEvent *e)
{

	popMenu = new QMenu(this);  
		
	popMenu->addAction(_showdowninfoAct);
	popMenu->addSeparator();
	popMenu->exec(e->globalPos());
} 

void DownloadsDialog::createActions()
{

  _showdowninfoAct = new QAction(QIcon(IMAGE_INFO), tr("Show Informations"), this);
  connect(_showdowninfoAct, SIGNAL(triggered()), this, SLOT(showDownInfoWindow()));
  


}

/** Shows Downloads Informations */
void DownloadsDialog::showDownInfoWindow()
{
    DownInfoWindow *downinfoWindow = new DownInfoWindow();
    downinfoWindow->show();
}

downlaodsdialog.h

Code: Alles auswählen

#ifndef _DOWNLOADSDIALOG_H
#define _DOWNLOADSDIALOG_H

#include <QFileDialog>

#include <config/rsharesettings.h>

#include "mainpage.h"
#include "ui_DownloadsDialog.h"



class DownloadsDialog : public MainPage 
{
  Q_OBJECT

public:
  /** Default Constructor */
  DownloadsDialog(QWidget *parent = 0);
  /** Default Destructor */


  
 

private slots:

  void showDownInfoWindow();
  
private:
  /** Create the actions on the tray menu or menubar */
  void createActions();
  /** Create the context popup menu and it's submenus */
  void contextMenuEvent( QContextMenuEvent *e);

  /** Define the popup menus for the Context menu */
  QMenu* popMenu;
  /** Defines the actions for the context menu */
  QAction* _showdowninfoAct;
  QAction* _resumeAct;

  /** Adds a new action to the toolbar. */
  void addAction(QAction *action, const char *slot = 0);

  /** Qt Designer generated object */
  Ui::DownloadsDialog ui;
};

#endif



oder hängt das von den stackedwidget ab?
da habe ich im Mainwindow auch zu custom geändert wegen contextmenu hat auch nichts gebracht.
Downloadsdialog ist ein Stackedwidget von mainwindow.

habe zu .ace gepackt weil das weniger ist als mit zip.
mit .zip wäre es zu groß als atachment.
-Marco-
Beiträge: 47
Registriert: 4. April 2006 16:35

Beitrag von -Marco- »

statt

Code: Alles auswählen

void contextMenuEvent( QContextMenuEvent *e);
nimm

Code: Alles auswählen

virtual void contextMenuEvent( QContextMenuEvent *e);
BTW: wenn einige Sachen nicht auf Anhieb funktionieren, bau ich mir immer ein kleines Testprojekt.
Gruß Marco
ChMaster
Beiträge: 252
Registriert: 23. Februar 2005 14:44
Wohnort: RP -> Alzey
Kontaktdaten:

Beitrag von ChMaster »

man ihr siet mir zu schnell :P
HEADER

Code: Alles auswählen

#ifndef _DOWNLOADSDIALOG_H
#define _DOWNLOADSDIALOG_H

#include <QFileDialog>

//#include <config/rsharesettings.h>

#include "mainpage.h"
#include "ui_DownloadsDialog.h"



class DownloadsDialog : public MainPage
{
  Q_OBJECT

public:
  /** Default Constructor */
  DownloadsDialog(QWidget *parent = 0);
  /** Default Destructor */





private slots:
  void showDownInfoWindow();
  /** Create the context popup menu and it's submenus */
  void downtreeWidgetCostumPopupMenu( QPoint point );

private:
  /** Create the actions on the tray menu or menubar */
  void createActions();
  void insertTransfers();

  /** Define the popup menus for the Context menu */
  QMenu* contextMnu;
  /** Defines the actions for the context menu */
  QAction* showdowninfoAct;
  QAction* _resumeAct;

  QTreeWidget *downtreeWidget;

  /** Adds a new action to the toolbar. */
  void addAction(QAction *action, const char *slot = 0);

  /** Qt Designer generated object */
  Ui::DownloadsDialog ui;
};

#endif
CPP

Code: Alles auswählen

#include "rshare.h"
#include "DownloadsDialog.h"
#include "downinfo/DownInfoWindow.h"
#include <QHeaderView>

#include <QContextMenuEvent>
#include <QMenu>
#include <QCursor>
#include <QPoint>
#include <QMouseEvent>

#include "rsiface/rsiface.h"

/* Images for context menu icons */
#define IMAGE_INFO       ":/images/informations_16x16.png"

/** Constructor */
DownloadsDialog::DownloadsDialog(QWidget *parent)
: MainPage(parent)
{
  /* Invoke the Qt Designer generated object setup routine */
  ui.setupUi(this);

  insertTransfers();

  connect( ui.downtreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( downtreeWidgetCostumPopupMenu( QPoint ) ) );

  /* Hide platform specific features */
#ifdef Q_WS_WIN

#endif
}


void DownloadsDialog::downtreeWidgetCostumPopupMenu( QPoint point )
{

      QMenu contextMnu( this );
      QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );

      showdowninfoAct = new QAction( tr( "Show Informations" ), this );
      connect( showdowninfoAct , SIGNAL( triggered() ), this, SLOT( showDownInfoWindow() ) );

      contextMnu.clear();
      contextMnu.addAction( showdowninfoAct);
      contextMnu.exec( mevent->globalPos() );
}

/** Shows Downloads Informations */
void DownloadsDialog::showDownInfoWindow()
{
    DownInfoWindow *downinfoWindow = new DownInfoWindow();
    downinfoWindow->show();
}

downtreeWidgetCostumPopupMenu(...) gehört in den slots block.

private slots:
void downtreeWidgetCostumPopupMenu( QPoint point );

so müsste es funtionieren.
Zuletzt geändert von ChMaster am 2. November 2006 23:17, insgesamt 1-mal geändert.
ChMaster
------------ Projekte------------
DBoxFE
DMS
First4 (Plugin-Develper)
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

es hat nichts gebracht ! leider.
geht immer noch nicht..
ChMaster
Beiträge: 252
Registriert: 23. Februar 2005 14:44
Wohnort: RP -> Alzey
Kontaktdaten:

Beitrag von ChMaster »

includier mal #include <QTreeWidget>
da ich es nicht seh .... in den sourcen ....
ChMaster
------------ Projekte------------
DBoxFE
DMS
First4 (Plugin-Develper)
Antworten