Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QRect>
- #include "Results.h"
- #include "MainWindow.h"
- #include "ui_MainWindow.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- m_ui(new Ui::MainWindow),
- m_results(0)
- {
- m_ui->setupUi(this);
- connect(m_ui->in_resultsInSeparateWin, SIGNAL(clicked()),
- this, SLOT(refreshResultsWindow()));
- refreshResultsWindow();
- }
- MainWindow::~MainWindow()
- {
- delete m_ui;
- delete m_results;
- }
- void MainWindow::refreshResultsWindow()
- {
- if(m_ui->in_resultsInSeparateWin->isChecked())
- {
- const int rWidth = m_results ? m_results->width() : 0;
- delete m_results;
- m_results = new Results();
- m_results->show();
- QWidget *widget = centralWidget();
- const int oldMaxWidth = maximumWidth();
- const int oldMaxWidgetWidth = widget->width();
- // This is configuration how resizing should be done:
- const int variant = 0;
- const bool useAlsoCentralWidget = true;
- // HERE! THIS IS THE PROBLEM AND WHAT IS NOT WORKING:
- switch(variant)
- {
- case 0:
- {
- // This doesn't work at all
- if(useAlsoCentralWidget)
- {
- widget->resize(widget->width() - rWidth, widget->height());
- }
- resize(width() - rWidth, height());
- }
- break;
- case 1:
- {
- if(useAlsoCentralWidget)
- {
- widget->setMaximumWidth(widget->width() - rWidth);
- }
- // This works only after when user moves main window
- setMaximumWidth(width() - rWidth);
- // (Note that later I want to reset maximum width to it's
- // original value, this is just only mean to force window to
- // resize.)
- // (Note that if central widget is resized too, it's needed to
- // reset maximum width later!)
- }
- break;
- case 2:
- {
- // This doesn't work at all
- if(useAlsoCentralWidget)
- {
- QRect g = widget->geometry();
- g.setWidth(g.width() - rWidth);
- widget->setGeometry(g);
- }
- QRect g = geometry();
- g.setX(g.x() - 10); // <-- this works
- g.setWidth(g.width() - rWidth); // <-- but this doesn't
- setGeometry(g);
- }
- break;
- case 3:
- {
- // This works well, but... it's SO ugly!
- setMaximumWidth(width() - rWidth);
- showMaximized();
- showNormal();
- setMaximumWidth(oldMaxWidth);
- }
- break;
- default:
- break;
- }
- }
- else
- {
- delete m_results;
- m_results = new Results();
- m_ui->layout_results->addWidget(m_results);
- }
- // NOTE: this is hardcoded because it's just example; in my real application
- // size changes depending on results!
- m_results->setMinimumSize(128, 128);
- m_results->setMaximumSize(128, 128);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement