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 490669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:55:58+00:00 2026-05-13T01:55:58+00:00

I am writing a small gui app with QT4.5 in QtCreator. The main screen

  • 0

I am writing a small gui app with QT4.5 in QtCreator.

The main screen on the app contains a QTreeView with two columns, the first is text the second is a group of icons. These icons represent the last few states of the item displayed in the row.

I am not sure what the best way to do this is. I have currently implemented this by generating a QPixmap the model’s data() method.

QVariant MyModel::data(const QModelIndex &index, int role) const
{
    if (role == Qt::DisplayRole || role == Qt::EditRole) {
        switch(index.column()) {
            case 0:
                return item_.at(index.row()).title();
        }
    }
    if (role == Qt::DecorationRole) {
        switch(index.column()) {
            case 1:
                return makeImage(item_.add(index.row()).lastStates());
        }
    }

    return QVariant();
}

QVariant MyModel::makeImage(const QList<MyState> &states) const
{
    const int IconSize = 22;
    QPixmap image(IconSize * states.size(), IconSize);
    QPainter painter(&image);

    painter.fillRect(0, 0, IconSize * count, IconSize, Qt::transparent);
    for (int i = 0; i < states.size(); ++i) {
        QIcon * icon = stateIcon(state.at(i));
        icon->paint(&painter, IconSize * i, 0, IconSize, IconSize);
    }
    return image;
}

This works but for some small problems, the background which should be transparent is full of random noise, even filling this with a transparent colour does not fix it.

Second this does not seem very efficient, I am generating a new Image every time this is called, should I not just draw the icons onto the widget for the cell?

What is the best way to display multiple icons in a single cell?

  • 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-13T01:55:59+00:00Added an answer on May 13, 2026 at 1:55 am

    I would create a custom delegate, based on a hbox, into which you can place all the pictures. Have a look at delegates in the Qt Documentation about model view programming.

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

Sidebar

Related Questions

I'm writing a small GUI app that contains some editor functionality, and something that
I am writing small app, using Play Framework 2.0 which uses Ebean as ORM.
I'm currently writing a small python app that embeds cherrypy and django using py2app.
I'm writing a NON-GUI app which I want to be cross platform between OS
I'm writing a small Java app using JavaMail that sends the user an automated
I'm looking at writing a portable, light-weight Python app. As the GUI toolkit I'm
I have been writing a small java application (my first!), that does only a
Hi am writing small app for posting twitts on twitter.com I manage to create
I'm writing a small app that requires a few listboxes, buttons, textboxes. It'll be
I'm writing a small sudoku game/solver in Linux using python with TUI (not GUI,

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.