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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:46:53+00:00 2026-06-17T11:46:53+00:00

I am working on a project that requires multiple instances to be placed inside

  • 0

I am working on a project that requires multiple instances to be placed inside a specific area. I am having trouble creating a function that will do that for me. Right now I have to manually set the value for each of the instances. How would I go about making a function that will take all the instances and place them evenly in a circle based on a radius?

Here is the area of code that I have where I manually set the placement. The function setIconWidgetLocation is what I have so far, just do not know what to place inside.

zMenuWidget::zMenuWidget(QWidget *parent) :
    QWidget(parent)
{
    icon1 = new iconWidget(this);
    icon2 = new iconWidget(this);
}

void zMenuWidget::resizeEvent(QResizeEvent *event)
{
    int yEndPosition = 0;
    int outerRadius = 100;
    int innerRadius = 60;

    QSizeF size = event->size();
    QPointF center(size.width(),size.height());
    center /= 2.0;

    yEndPosition = (outerRadius - innerRadius)/2.0 + innerRadius;
    yEndPosition = center.y() - yEndPosition;

    int yCurrIconLoc = icon1->rect().center().y();
    int xCurrIconLoc = icon1->rect().center().x();

    icon1->move(center.x() - xCurrIconLoc, yEndPosition - yCurrIconLoc);
}

void setIconWidgetLocation(iconWidget* w, float angle)
{

}
  • 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-06-17T11:46:55+00:00Added an answer on June 17, 2026 at 11:46 am

    I’m fairly certain that this is precisely what QLayout is for. You can derive your own class from that and use it to layout its widgets radially.

    But just going on what you have now, forget that… You just want simple placement. You will need to iterate through all your icons. Presumably you have them stored in an array.

    To do this, you need to know the radius of your circle, which seem to have hard-coded. What you probably want is to align your icon centres on the circle, so you need to subtract half the icon size from your outer radius. But I see you have both an outer and inner radius. So let’s just put the icon centres in the middle of that:

    int radius = (outerRadius + innerRadius) / 2;
    

    And all you’re really doing here is maths. Circles are easy. You decide what angle of arc is subtended for each icon. That’s up to you. You might calculate it so that icons don’t collide, or you might make it constant, or you might evenly space your icons.

    But you seem to want evenly-spaced icons, so that’s easy. Each icon occupies a slice of the pie, which in radians is Tau, more traditionally known as 2Pi.

    float arcSize = 2.0 * M_PI / numIcons;
    

    Every circle needs a centre and a radius. Now you just need to decide where to begin. The angle zero is typically on the right (an offset of radius horizontally and zero vertically), but you probably want it at the top. We can either add a quarter revolution (Tau/4) or we can just flip the maths.

    Normally the formula for a circle is:

    x = cx + r * cos(angle);
    y = cy - r * sin(angle);   // Assuming screen co-ordinates
    

    But if I want to start this at the top (still rotating anti-clockwise), I do this:

    x = cx - r * sin(angle);   // Flip the minus sign if you want clockwise.
    y = cy - r * cos(angle);
    

    Now all that’s left to do is find the centres of all your icons and position them:

    for( int i = 0; i < numIcons; i++ )
    {
        // Find icon centre on circle
        double x = centreX + radius * sin(arcSize * i);
        double y = centreY - radius * cos(arcSize * i);
    
        // Offset to get the top-left of your icon
        x -= iconWidth / 2;
        y -= iconHeight / 2;
    
        // And position it with your Qt call, whatever that may be.
        icon[i]->move(x, y);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project for my companies intranet which requires that multiple attached
I am working on a project that requires an object to have multiple values.
I'm working on a project that requires to convert html email into text. Below
I am working on a project that requires me to define a DSL. Since
I'm working on a project that requires a fair bit of inserting/updating rows in
I am working on a project that requires some image processing. The front end
Currently am working on a project that requires me to create some XML for
I'm working on a project that requires me to programmatically create MySQL users from
I'm working on a project that requires a Web-based workflow application. We're now evaluating
I am currently working on a project that requires me to display PDF documents

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.