在QT中,當點擊一個按鈕並彈出一個窗口時,用戶仍然可以返回並單擊相同的按鈕(無限次)。我該如何做到這一點,以便從按鈕彈出的窗口保持在其他窗口之上? 在這種情況下,它是彈出窗口的「編輯」按鈕。如何使彈出式窗口成爲QT中的頂級窗口?
這裏是window.cpp
#include "window.h"
#include "editwindow.h"
#include "ui_window.h"
#include <QtGui/QApplication>
#include <QtGui>
Window::Window(QWidget *parent) :
QDialog(parent),
ui(new Ui::Window)
{
ui->setupUi(this);
ShowEdit = new QPushButton(tr("Edit"));
ShowEdit -> show();
connect(ShowEdit, SIGNAL(clicked()), this, SLOT(popup()));
Remove = new QPushButton(tr("Remove"));
Remove -> show();
connect(Remove, SIGNAL(clicked()), this, SLOT(ProgramRemove()));
OK = new QPushButton(tr("OK"));
OK -> show();
connect(OK, SIGNAL(clicked()), this, SLOT(Saved()));
Quit = new QPushButton(tr("Quit"));
Quit -> show();
connect(Quit, SIGNAL(clicked()), this, SLOT(close()));
QLabel *tableLabel = new QLabel(tr("All Programs"));
QVBoxLayout *buttonLayout2 = new QVBoxLayout;
buttonLayout2 -> addWidget(ShowEdit);
buttonLayout2 -> addWidget(Remove);
//buttonLayout2 -> addStretch();
QHBoxLayout *buttonLayout2_2 = new QHBoxLayout;
buttonLayout2_2 -> addWidget(Quit);
buttonLayout2_2 -> addWidget(OK);
/*******************************************************************************/
/***************************Below is for Table**********************************/
/*******************************************************************************/
PTable = new QTableWidget(10, 10);
//PTable ->setHorizontalHeader(tr("Program Names"));
//inputs->setText(QString::number(row));
//PTable->setItem(row, column, inputs);
QHBoxLayout *PTableLayout = new QHBoxLayout;
PTableLayout ->addWidget(PTable);
/*------------------------------------------------------------------------------*/
/*------------------------construct window--------------------------------------*/
/*------------------------------------------------------------------------------*/
QGridLayout *SecondLayout = new QGridLayout;
SecondLayout -> addWidget(tableLabel, 0, 0);
SecondLayout -> addLayout(PTableLayout, 1, 0);
SecondLayout -> addLayout(buttonLayout2, 0, 1);
SecondLayout -> addLayout(buttonLayout2_2, 2, 0);
setLayout(SecondLayout);
setWindowTitle(tr("Settings"));
}
Window::~Window()
{
delete ui;
}
void Window :: popup()
{
EditWindow* window_3 = new EditWindow(this);
window_3->move(QPoint(550, 100));
window_3->show();
window_3->raise();
}
void Window :: closeBoth()
{
return;
}
void Window :: Saved()
{
return;
}
void Window :: ProgramRemove()
{
return;
}
我把它放在'void Window :: popup()',它最終崩潰的程序。我也評論了'window_3 - > show();' – Chris 2011-03-03 00:48:50