[Solved] Having trouble using QMdiArea.



  • I would really appreciate if somebody could help me with using the QMdiArea class. I'm kind of stumped, why the code below isn't working.

    I have no problem displaying subwindows when I add them in the MainWindow::MainWindow() constructor. However, when I try to do this is in a slot function NOTHING appears in the MDI area. What's going on?

    Here is the code I am using that isn't doing what I want.
    MainWindow.h
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    public slots:
    void display_images();

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H
    @

    MainWIndow.cpp
    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QPushButton *display_action_button = new QPushButton();
    
    ui->imageDisplayWindowsArea->addSubWindow(display_action_button);
    connect(display_action_button, SIGNAL(clicked()), this, SLOT(display_images()));
    
    ui->imageDisplayWindowsArea->cascadeSubWindows();
    

    }

    void MainWindow::display_images()
    {
    QString full_path = "C:\Users\me\Downloads\o-png8.png";

    QString qstyle = "background: url";
    qstyle.append("(");
    qstyle.append(full_path);
    qstyle.append(")");
    
    QWidget* imageDisplayWidget = new QWidget();
    imageDisplayWidget->setWindowFlags(Qt::Popup);
    imageDisplayWidget->setStyleSheet(qstyle);
    QPixmap * mypix = new QPixmap(full_path);
    int ih = mypix->height();
    int iw = mypix->width();
    QSize size(iw, ih);
    imageDisplayWidget->resize(size);
    
    
    QMdiSubWindow *subWindow1 = new QMdiSubWindow;
    subWindow1->setWidget(imageDisplayWidget);
    subWindow1->setWindowTitle("Image Display");
    subWindow1->resize(size);
    subWindow1->setAttribute(Qt::WA_DeleteOnClose);
    
    ui->imageDisplayWindowsArea->addSubWindow(subWindow1);
    

    }
    @

    Thanks in advance for any help.



  • I believe I resolved my own question. Looks like you have to call the show() method of the subwindow. DUH.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    great you found out by yourself !

    Could you also update the thread's title so other forum members will know a solution has been found ? :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.