我有QDialog
很多设计QDesigner
,我在网上看到我可以添加如下QStatusBar
代码:
#include <QDialog>
#include <QStatusBar>
#include <QLayout>
#include <QApplication>
#include <QTextEdit>
#include <QStatusTipEvent>
class Dialog : public QDialog {
public:
Dialog() : QDialog(){
QLayout *l = new QVBoxLayout(this);
QTextEdit *te = new QTextEdit;
te->setStatusTip("XXX");
l->addWidget(te);
bar = new QStatusBar;
l->addWidget(bar);
l->setMargin(0);
l->setSpacing(0);
}
private:
QStatusBar *bar;
protected:
bool event(QEvent *e){
if(e->type()==QEvent::StatusTip){
QStatusTipEvent *ev = (QStatusTipEvent*)e;
bar->showMessage(ev->tip());
return true;
}
return QDialog::event(e);
}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
Dialog dlg;
return …
Run Code Online (Sandbox Code Playgroud) 这次我真的不知道如何提出我的问题......
我有一个QDialog作为主窗口的应用程序.应用程序从远程机器获得不同的值,如温度,湿度等.
为了开发,我添加了一个包含不同小部件的组框来模拟这些值.我向用户投掷警告和警报有不同的限制.
例如,如果温度上升超过30°C,那么我打开一个带有请求时间的QMessageBox(应用程序在远程机器上进行轮询)和当前温度.所以每个请求周期都会更新.
我使用show()方法调出消息框,使我的应用程序在后台运行.现在的问题是:焦点在消息框中,我的主窗口/ QDialog中没有任何内容可以被点击,直到消息框不被接受/已经完成.
这就是我的问题:在模拟模式下,我想要使用不同的温度值,我可以通过主窗口中的滑块来调整.如何访问这些小部件/使消息框以某种方式"不阻塞"?
最好的祝福,
马蒂亚斯
所以,我正在使用Python和PyQt.我有一个包含QTableWidget的主窗口,以及一个以模态方式打开并具有一些QLineEdit小部件的对话框......好了到目前为止,但我有两个问题:
对话框打开后,我的主窗口冻结了,我真的不喜欢那样......
当我完成编辑QLineEdit时,我想要的是程序将搜索QTableWidget,如果表中存在QLineEdit中的文本,则会出现一个对话框,并提供相关信息.这是一般的想法.但是,到目前为止,我似乎只能创建一个新的QTableWidget实例,而我无法使用现有的数据...
我能做些什么呢?
I\xe2\x80\x99m 在 X11 上使用 Qt 4.8.3。
\n我需要知道用户何时结束在屏幕上拖动窗口,\n这是为了读取最终位置并最终启动动画以将窗口位置调整为 \xe2\x80\x9callowed\xe2\x80\x9d 。
\n我注意到QWidget::moveEvent
每个小移动都会调用 ,但这非常不方便,因为只有当用户释放鼠标按钮并且移动完全完成时我才必须执行位置检查(并最终启动动画)。
这是真正的问题:当用户单击标题栏时,似乎无法检测鼠标释放事件(或获取鼠标按钮状态),因为它是由操作系统而不是 Qt 控制的。\nI还尝试使用QWidget::x11event(XEvent* e)
\xe2\x80\xa6 但事件仅收集在窗口内,而不是标题栏内。
有人知道如何实现这一目标吗?
\n我怀疑我必须自己重新实现标题栏\xe2\x80\xa6 太糟糕了\xe2\x80\xa6
\n我需要Qt Dialog和ok并取消具有标准功能的按钮,放置在其布局的右侧.我需要继承它并在其布局中添加其他小部件.我可以自己实现它,但也许有标准的东西,在这种情况下我更喜欢使用它,因为它会更便携.
QMessageBox显示一条消息,我需要更通用的东西,只需要QDialog和标准按钮,或者QDialog有一个激活它们的选项.
在我的Qt应用程序中,我面临以下情况:当引发特定事件时,我显示无模式QDialog
,要求用户进行确认.使用show()
来自a的函数显示对话框QMainWindow
.无论何时引发事件并且未显示其他模态QDialog
,用户都可以单击确认按钮.不幸的是,如果在QDialog
引发事件时可以看到模态,QDialog
则无模式是无法访问的.这意味着用户无法单击确认按钮.以下代码是导致相同问题的简化版本在此示例中QMainWindow
包含一个按钮,当单击按钮时,QDialog
使用该exec()
函数显示模态,同时a QTimer
已启动.无论何时我QDialog
在QTimer
经过之前关闭模态,都可以访问无模式对话框.如果我等到显示无模式对话框而没有关闭模态对话框,则无法访问无模式对话框(我需要先关闭模态对话框).
MainWindows代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_pModeless = new DialogModal(this);
connect(&m_qTimer,SIGNAL(timeout()),this,SLOT(TimerElapsed()));
}
MainWindow::~MainWindow()
{
delete m_pModeless;
delete ui;
}
void MainWindow::TimerElapsed()
{
m_qTimer.stop();
m_pModeless->show();
m_pModeless->activateWindow();
m_pModeless->raise();
m_pModeless->setFocus();
}
void MainWindow::on_pbStartTest_clicked()
{
m_qTimer.start(10000);
DialogModal d(this);
d.exec();
}
Run Code Online (Sandbox Code Playgroud)
MainWindow标题:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include "dialogmodal.h"
namespace …
Run Code Online (Sandbox Code Playgroud) 我正在使用 pyqt5 和 QtDesigner 创建一个具有两个窗口的应用程序。主窗口“MainWindow.ui”上的按钮应该从文件“age_entry.ui”打开第二个窗口,但我似乎遗漏了一些东西。单击第一个表单上的按钮会产生此错误”:
异常“未处理的TypeError”QDialog(父:QWidget = None,标志:Union [Qt.WindowFlags,Qt.WindowType] = Qt.WindowFlags()):参数1具有意外类型'bool'
这是主窗口的代码:
# -*- coding: utf-8 -*-
import sys
from PyQt5 import uic, QtWidgets
Ui_MainWindow, QtBaseClass = uic.loadUiType("MainWindow.ui")
LandingPageUI, LandingPageBase = uic.loadUiType("age_entry.ui")
class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
def showAgeEntryForm(self):
self.child_win = AgeEntryForm(self)
self.child_win.show()
self.btnOpenAges.clicked.connect(showAgeEntryForm)
class AgeEntryForm(LandingPageBase, LandingPageUI):
def __init__(self, parent=None):
LandingPageBase.__init__(self, parent)
self.setupUi(self)
if __name__ == "__main__":
app=QtWidgets.QApplication.instance()
if not app:
app = QtWidgets.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
提前致谢!
这是代码形式的MainWindow和age_entry文件:
# -*- coding: utf-8 -*-
# …
Run Code Online (Sandbox Code Playgroud) 我正在制作一个测试程序,其中 MainWindow 用作登录屏幕。用户输入用户名和密码。如果它们与分配给字符串的内容匹配,则会出现对话框。如果失败,则会出现 QMessageBox。
我的问题是当我希望对话框出现(主程序)时,我希望登录页面消失。命令 close(); 只会关闭一切。
这是 MainWindow.cpp 的代码(对话框在标题中被引用为名为 mDialog 的 POINTER)
void MainWindow::on_pushButton_clicked()
{
if (ui->lineEdit->text() == username)
{
if (ui->lineEdit_2->text() == password)
{
//This is where the Dialog appears
mDialog= new MyDialog(this);
mDialog->show();
}
}
else if (ui->lineEdit->text() != username || ui->lineEdit->text() ==NULL)
{
if (ui->lineEdit_2->text() != password || ui->lineEdit_2->text() == NULL)
{
QMessageBox::warning(this, "Error", "The username or password is incorrect.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是 main.cpp 的代码
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow …
Run Code Online (Sandbox Code Playgroud) 我有这个示例代码:
QDialog *dialog = new QDialog(this);
QPoint dialogPos = dialog->mapToGlobal(dialog->pos());
QPoint thisPos = mapToGlobal(this->pos());
dialog->exec();
Run Code Online (Sandbox Code Playgroud)
但是Dialog并不以他的父母为中心.提前致谢.
更新:
我在MainWindow中从构造函数调用Dialog:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->panelInferior = new WidgetTabsInferior;
this->acciones = new Acciones(this);
crearAcciones();
crearBarraMenu();
crearToolbar();
crearTabsEditor();
crearArbolDir();
crearDockWindows();
crearStatusBar();
setWindowIcon(QIcon(":imgs/logo.png"));
connect(this->pestanasEditor , SIGNAL(currentChanged(int)),this,SLOT(cambioTab(int)));
this->dialogo = new AcercaDe(this);
this->dialogo->move(x() + (width() - dialogo->width()) / 2,
y() + (height() - dialogo->height()) / 2);
this->dialogo->show();
this->dialogo->raise();
this->dialogo->activateWindow();
}
Run Code Online (Sandbox Code Playgroud)
但我得到的是:
qdialog ×10
qt ×9
c++ ×5
qmainwindow ×3
pyqt ×2
qt4 ×2
blocking ×1
button ×1
childwindow ×1
dialog ×1
focus ×1
modal-dialog ×1
modeless ×1
pyqt5 ×1
python ×1
qbuttongroup ×1
qmessagebox ×1
qt4.8 ×1
qt5 ×1