// main.cpp#include <qapplication.h>#include <qwidget.h>#include <qlistbox.h>#include <qsizegrip.h>#include <qlayout.h>#include <qlineedit.h>class Popup : public QWidget{ Q_OBJECTpublic: Popup( QWidget* parent = 0, const char* name = 0 ) : QWidget( parent, name, WType_Popup | WStyle_NormalBorder ) { edit = new QLineEdit( this ); QSizeGrip* grip = new QSizeGrip( this ); QHBoxLayout* mainLayout = new QHBoxLayout( this ); mainLayout->addWidget( edit ); mainLayout->addWidget( grip ); } public slots: void popup( QListBoxItem* item, const QPoint& p) { move( p ); if ( item ) edit->setText( item->text() ); else edit->setText(""); show(); }private: QLineEdit* edit;};int main( int argc, char** argv ){ QApplication app( argc, argv ); QObject::connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); QListBox lb; lb.insertItem( "One" ); lb.insertItem( "Two" ); lb.insertItem( "Three" ); Popup pp; QObject::connect( &lb, SIGNAL( contextMenuRequested(QListBoxItem*, const QPoint&) ), &pp, SLOT( popup(QListBoxItem*, const QPoint&) ) ); lb.show(); return app.exec(); }#include "main.moc"