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. Reducing the size of a QMdiSubWindow holding a QLabel with QPixmap
Forum Updated to NodeBB v4.3 + New Features

Reducing the size of a QMdiSubWindow holding a QLabel with QPixmap

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.5k 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.
  • B Offline
    B Offline
    Balajee
    wrote on last edited by
    #1

    The question statement says it all. I am able to enlarge the QMdiSubWindow (and the pixmap scales UP, i.e. enlarges, appropriately) but I am not able to reduce its size (i.e. scale the image DOWN or shrink). When trying to scale down though, the border handles of the QMdiSubWindow remain rigidly fixed.

    The code I am using is as follows:
    @class PixmapWidget : public QLabel
    {
    Q_OBJECT
    public:
    PixmapWidget():
    QLabel()
    {
    _pixmap = QPixmap("path\to\images.jpg");
    setPixmap(_pixmap);
    _layout = new QHBoxLayout();
    _layout->setSizeConstraint(QLayout::SetNoConstraint);
    setLayout(_layout);
    setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
    }

    void resizeEvent(QResizeEvent * event)
    {
        int width = event->size().width();
        int height = event->size().height();
        setPixmap(_pixmap.scaled(width,height));
        QLabel::resizeEvent(event);
    }
    

    protected:
    QPixmap _pixmap;
    QHBoxLayout* _layout;
    };

    int main()
    {
    QMainWindow mainWindow;
    QHBoxLayout* layout = new QHBoxLayout();
    QMdiArea* mdiArea = new QMdiArea();

    mainWindow.setCentralWidget(mdiArea);
    mainWindow.centralWidget()->setLayout(layout);
    layout->setSizeConstraint(QLayout::SetNoConstraint);
    
    QMdiSubWindow* mdiSubWindow = new QMdiSubWindow();
    layout->addWidget(mdiSubWindow);        
    mdiSubWindow->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
    mdiSubWindow->layout()->setSizeConstraint(QLayout::SetNoConstraint);
    
    DMSQt::PixmapWidget pixmapWidget;        
    mdiSubWindow->layout()->addWidget(&pixmapWidget);
    
    mainWindow.show();
    qapp.exec();
    

    }@

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Balajee
      wrote on last edited by
      #2

      Alright, I found the problem. Apparently, I need to set a minimum size on my text label:

      Adding:

      @setMinimumSize(_pixmap.width(), _pixmap.height());@

      solved the problem.

      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