Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Having trouble using QMdiArea.

[Solved] Having trouble using QMdiArea.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chooser
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chooser
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 ? :)

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved