2011-03-03 6 views
1

QT에서 버튼을 클릭하고 창이 팝업되면 사용자는 계속 돌아가 동일한 버튼을 클릭 할 수 있습니다 (무한 시간). 버튼에서 튀어 나오는 창이 다른 창 위에 놓 이도록 어떻게 만들 수 있습니까? 이 경우 창을 팝업하는 것은 "편집"버튼입니다. EditWindow가 대신 쇼의 간부 인 방법을 호출 할 수있는 QDialog 경우 여기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; 
} 

답변

3

입니다. Qt는 문서에서

:

INT 인 QDialog :: 간부() [슬롯]

모달 대화 등의 대화, 차단 사용자가 닫을 때까지를 표시합니다. 함수는 DialogCode 결과를 반환합니다.

대화 상자가 응용 프로그램 모달 인 경우 사용자는 대화 상자를 닫을 때까지 동일한 응용 프로그램에서 다른 창과 상호 작용할 수 없습니다. 대화 상자 이 창 모달 인 경우 대화 상자가 열려있는 동안 부모 창과의 상호 작용 만 차단됩니다. 기본적으로 대화 상자 은 응용 프로그램 모달입니다.

이렇게하면 EditWindow가 열려있는 동안 사용자가 부모 창과 상호 작용할 수 없습니다.

4

이것은 QDialog이 모달이 아니기 때문에 다른 창에 대한 입력을 차단하지 않기 때문입니다.

QDialog (Description of Modality in QT)에 setWindowModality()을 사용하여이 속성을 설정할 수 있습니다. 기본적으로 다음과 같이하면됩니다 :

setWindowModality(Qt::WindowModal); 
+0

void Window :: popup()'에 넣으면 프로그램이 종료됩니다. 나는 또한'window_3 -> show();를 주석 처리했다. – Chris

관련 문제