Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5966403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:47:43+00:00 2026-05-22T19:47:43+00:00

I’m making a program that will display a few images from a directory beside

  • 0

I’m making a program that will display a few images from a directory beside each other.

When I scale the images to fit within the height of the window (ie – QGraphicsPixmapItem->scale(…)), it runs fairly well in windows, but runs unbearably slow in linux (Ubuntu 11.04).

If the images are not scaled, performance is similar on both systems.

I’m not sure if it has to do with the way each OS caches memory, since when I run the program under Linux, the memory used is always constant and around 5mb, when it’s closer to 15-30mb under Windows depending on the images loaded.

Here is the related code:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    scene = new QGraphicsScene(this);
    view = new QGraphicsView(scene);
    setCentralWidget(view);
    setWindowTitle(tr("ImgVw"));
    bestFit = true;

    view->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
    view->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
    view->setDragMode(QGraphicsView::ScrollHandDrag);
    view->setStyleSheet( "QGraphicsView { border-style: none; padding: 5px; background-color: #000; }" );   // set up custom style sheet

    // Get image files from folder
    QDir dir("test_img_folder");
    QStringList fileList = dir.entryList();
    fileList = fileList.filter(QRegExp(".*(\.jpg|\.jpeg|\.png)$"));

    // Create graphics item for each image
    int count = 0;
    foreach(QString file, fileList)
    {
    if (count >= 0)
    {
        QPixmap g(dir.absolutePath() + QString("/") + file);
        scene->addPixmap(g);
    }
    count++;
    if (count >= 5) break;
    }
}

void MainWindow::resizeEvent(QResizeEvent *event)
{
    int pos = 0;
    foreach(QGraphicsItem *item, scene->items(Qt::AscendingOrder))
    {
        double ratio = 1.0;
        QGraphicsPixmapItem *pixmapItem = (QGraphicsPixmapItem*) item;

        // Resize to fit to window
        if (bestFit) {
            double h = (double) (view->height()-10)/pixmapItem->pixmap().height();
            ratio = min(h, 1.0);
            pixmapItem->setScale(ratio);
        }

        // Position 5 pixels to the right of the previous image
        item->setPos(pos,0);
        pos += pixmapItem->pixmap().width()*ratio + 5;
    }

    // Resize scene to fit items
    scene->setSceneRect(scene->itemsBoundingRect());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:47:44+00:00Added an answer on May 22, 2026 at 7:47 pm

    You could try different graphicssystems e.g. with the command line switch -graphicssystem raster|native|opengl or by setting the environment variable QT_GRAPHICSSYSTEM to “raster” etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.