QMessagebox for IOS开发的任何替代解决方案(仅限QWidget应用程序)? [英] Any alternative solution for QMessagebox for IOS development (QWidget application only)?

查看:564
本文介绍了QMessagebox for IOS开发的任何替代解决方案(仅限QWidget应用程序)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Qt 5.3并尝试为IOS开发应用程序。

I am using Qt 5.3 and trying to develop application for IOS.

问题是,iPhone Retina模拟器中的QWidget应用程序:

Problem is, QWidget application in a iPhone Retina simulator:


  1. QMessage变为全屏。

  2. 在应用程序输出面板中,我看到:此插件不支持
    propagateSizeHints() 。

所以寻找QMessageBox的替代解决方案。我还不想学习QML。

So looking for alternative solution for QMessageBox. I don't want to learn QML yet.

推荐答案

如果你在你的小工具上做一个叠加,你可以做类似的东西到iOS弹出窗口。

If you do an overlay on top of your widget you can make something similar to the iOS popups.

基本上你创建了另一个小部件,并且你将它放到你希望它被绘制的小部件上。

Basically you create another widget, and you parent it to the widget you want it to be drawn on top of.

以下是一些有用的标记和代码行,放在你的覆盖构造函数中:

Here are some helpful flags and lines of code to put in your overlay constructor:

setPalette(Qt::transparent);
// if you have buttons on this overlay you probably don't want this one
setAttribute(Qt::WA_TransparentForMouseEvents);

QGraphicsDropShadowEffect * dse = new QGraphicsDropShadowEffect();
dse->setBlurRadius(20);
this->setGraphicsEffect(dse);

然后确保在父窗口小部件调整大小时命令调整叠加层的大小:

Then be sure to command a resize of your overlay when the parent widget resizes:

void ParentWidget::resizeEvent(QResizeEvent *event)
{
    overlay->resize(event->size());
    event->accept();
}

http://www.qtcentre.org/wiki/index.php?title=Widget_Overlay

更新:很棒的例子

main.cpp

#include <QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    w.resize(300,600);

    return a.exec();
}

mainwindow.h

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "overlaydialogbox.h"
#include <QResizeEvent>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
public slots:
    void resizeEvent(QResizeEvent *event);

private:
    OverlayDialogBox * m_overlay;
};

#endif // MAINWINDOW_H

mainwindow.cpp

mainwindow.cpp

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    m_overlay = new OverlayDialogBox(this);
}

MainWindow::~MainWindow() { }

void MainWindow::resizeEvent(QResizeEvent *event)
{
    m_overlay->resize(event->size());
    event->accept();
}

overlaydialogbox.h

overlaydialogbox.h

#ifndef OVERLAYDIALOGBOX_H
#define OVERLAYDIALOGBOX_H

#include <QWidget>

class OverlayDialogBox : public QWidget
{
    Q_OBJECT
public:
    explicit OverlayDialogBox(QWidget *parent = 0);

signals:
    void accepted();
    void rejected();
    void finished(int);
public slots:
};

#endif // OVERLAYDIALOGBOX_H

overlaydialogbox.cpp

overlaydialogbox.cpp

#include "overlaydialogbox.h"
#include <QGridLayout>
#include <QGraphicsEffect>
#include <QLabel>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QIcon>

OverlayDialogBox::OverlayDialogBox(QWidget *parent) :
    QWidget(parent)
{
    setPalette(Qt::transparent);
    // if you have buttons on this overlay you probably don't want this one
//    setAttribute(Qt::WA_TransparentForMouseEvents);

    QGraphicsDropShadowEffect * dse = new QGraphicsDropShadowEffect();
    dse->setBlurRadius(20);
    this->setGraphicsEffect(dse);

    QGridLayout * grid = new QGridLayout();
    this->setLayout(grid);

    QMessageBox * msg = new QMessageBox(QMessageBox::Warning,"Testing","This is a test QMessageBox.");
    QObject::connect(msg, SIGNAL(accepted()), this, SIGNAL(accepted()));
    QObject::connect(msg, SIGNAL(finished(int)), this, SIGNAL(finished(int)));
    QObject::connect(msg, SIGNAL(rejected()), this, SIGNAL(rejected()));
    QObject::connect(msg, SIGNAL(finished(int)), this, SLOT(close()));

    msg->setPalette(Qt::white);

    grid->addWidget(msg);
}

希望有所帮助。

这篇关于QMessagebox for IOS开发的任何替代解决方案(仅限QWidget应用程序)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆