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. new Widget not following parent window size

new Widget not following parent window size

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 205 Views
  • 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.
  • R Offline
    R Offline
    Ragbot
    wrote on last edited by
    #1

    Hey guys im tyringto make it so that
    when I double click on list it show shows me the items details but when I do that the new widget that I call does not follow the constraints I tried setting it as central widget but it does not go back to the old page if do that what should I do this is my code

    mainwindow.cpp

    #include "mainwindow.h"
    #include "./ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        manga = new MangaDex();
        viewer = new MangaViewer(this);
        viewer->hide();
    }
    
    MainWindow::~MainWindow()
    {
        delete manga;
        delete ui;
    }
    
    void MainWindow::on_SearchButton_clicked()
    {
        manga_list = manga->search(ui->SearchEntry->text().toStdString());
    
        ui->Pages->clear();
    
        for (Manga i: manga_list)
        {
            ui->Pages->addItem(i.title.c_str());
        }
    }
    
    
    void MainWindow::on_SearchEntry_returnPressed()
    {
        this->on_SearchButton_clicked();
    }
    
    void MainWindow::on_Pages_itemDoubleClicked(QListWidgetItem *item)
    {
    //    item->listWidget()->takeItem(item->listWidget()->row(item));
        int row = item->listWidget()->row(item);
        show_manga(&this->manga_list.at(row));
    }
    
    
    void MainWindow::on_Options_clicked()
    {
        ui->Pages->setHidden(!ui->Pages->isHidden());
    }
    
    
    void MainWindow::on_pushButton_2_clicked()
    {
        show_manga(0);
    }
    
    void MainWindow::show_manga(Manga* manga)
    {
        ui->MainView->hide();
        connect(viewer, &MangaViewer::signal_close, this, [this]{
            this->ui->MainView->show();
        });
        viewer->setManga(manga);
        viewer->show();
    }
    

    mangaviewer.cpp:

    #include "mangaviewer.h"
    #include "ui_mangaviewer.h"
    
    MangaViewer::MangaViewer(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::MangaViewer)
    {
        ui->setupUi(this);
        this->setParent(parent);
        this->manga = new Manga{
            .id = "",
            .title = ""
        };
    
        ui->image->setPixmap(QPixmap("notfound.jpg"));
    }
    
    MangaViewer::~MangaViewer()
    {
        delete manga;
        delete ui;
    }
    
    void MangaViewer::on_pushButton_clicked()
    {
        emit signal_close();
        close();
    }
    
    Manga *MangaViewer::getManga() const
    {
        return manga;
    }
    
    void MangaViewer::setManga(Manga *newManga)
    {
        if (!(newManga == nullptr)) manga = newManga;
        else {manga->id = ""; manga->title = "";}
        ui->title_label->setText(manga->title.c_str());
    }
    
    void MangaViewer::on_read_button_clicked()
    {
        emit signal_close();
        close();
    }
    
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • R Ragbot

      Hey guys im tyringto make it so that
      when I double click on list it show shows me the items details but when I do that the new widget that I call does not follow the constraints I tried setting it as central widget but it does not go back to the old page if do that what should I do this is my code

      mainwindow.cpp

      #include "mainwindow.h"
      #include "./ui_mainwindow.h"
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          manga = new MangaDex();
          viewer = new MangaViewer(this);
          viewer->hide();
      }
      
      MainWindow::~MainWindow()
      {
          delete manga;
          delete ui;
      }
      
      void MainWindow::on_SearchButton_clicked()
      {
          manga_list = manga->search(ui->SearchEntry->text().toStdString());
      
          ui->Pages->clear();
      
          for (Manga i: manga_list)
          {
              ui->Pages->addItem(i.title.c_str());
          }
      }
      
      
      void MainWindow::on_SearchEntry_returnPressed()
      {
          this->on_SearchButton_clicked();
      }
      
      void MainWindow::on_Pages_itemDoubleClicked(QListWidgetItem *item)
      {
      //    item->listWidget()->takeItem(item->listWidget()->row(item));
          int row = item->listWidget()->row(item);
          show_manga(&this->manga_list.at(row));
      }
      
      
      void MainWindow::on_Options_clicked()
      {
          ui->Pages->setHidden(!ui->Pages->isHidden());
      }
      
      
      void MainWindow::on_pushButton_2_clicked()
      {
          show_manga(0);
      }
      
      void MainWindow::show_manga(Manga* manga)
      {
          ui->MainView->hide();
          connect(viewer, &MangaViewer::signal_close, this, [this]{
              this->ui->MainView->show();
          });
          viewer->setManga(manga);
          viewer->show();
      }
      

      mangaviewer.cpp:

      #include "mangaviewer.h"
      #include "ui_mangaviewer.h"
      
      MangaViewer::MangaViewer(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::MangaViewer)
      {
          ui->setupUi(this);
          this->setParent(parent);
          this->manga = new Manga{
              .id = "",
              .title = ""
          };
      
          ui->image->setPixmap(QPixmap("notfound.jpg"));
      }
      
      MangaViewer::~MangaViewer()
      {
          delete manga;
          delete ui;
      }
      
      void MangaViewer::on_pushButton_clicked()
      {
          emit signal_close();
          close();
      }
      
      Manga *MangaViewer::getManga() const
      {
          return manga;
      }
      
      void MangaViewer::setManga(Manga *newManga)
      {
          if (!(newManga == nullptr)) manga = newManga;
          else {manga->id = ""; manga->title = "";}
          ui->title_label->setText(manga->title.c_str());
      }
      
      void MangaViewer::on_read_button_clicked()
      {
          emit signal_close();
          close();
      }
      
      
      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You have to add your widget to the parents layout.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

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