Active Topics

 


Reply
Thread Tools
eitama's Avatar
Posts: 702 | Thanked: 334 times | Joined on Feb 2010 @ Israel.
#1
Basically,

I have a frame, I am going to fill it with arbitrary number of buttons, each button will have a letter in it.

I want to have about 4 buttons every row.
Now the catch :
- If there is only 1 row, and 1 button in that row, I want the button to take the size of the whole frame.
- If there is 1 row, with 2 buttons, I want those 2 buttons to share the size of the whole frame.
- etc...

The point being, always use maximum space, and when i add new buttons, i want to reduce the buttons size.
Can this be done automatically with layouts? grid didn't do it so well.
I don't want any spaces or margins between the buttons at all.

Any ideas?

Reminder, this needs to be at runtime, i can't use the designer for this.

Any help will be much appreciated!
__________________
| Developer of Horizontal-Call - Call your contacts, fast! |
| Reverse SSH - access your N900 from anywhere, anytime |
| Using Samsung Galaxy S GT-i9000 and Nokia N900 |
| DonateMe - If you feel I helped you in a very good way, feel free to donate |

Last edited by eitama; 2010-06-16 at 15:06.
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#2
Isn't this what you use HBoxes for?

Create a new HBox, add the buttons you need, and replace the old HBox (if there is one).
 
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#3
Originally Posted by Joorin View Post
Isn't this what you use HBoxes for?

Create a new HBox, add the buttons you need, and replace the old HBox (if there is one).
To a point. He'll still have spacing around the Buttons (widgets).

We can use the example I already posted over here that talked about popping up boxes in qdialog because this is very similar. I created a Dialog, 2 HBoxLayouts, and then added buttons on the fly.

Now, the default behavior of all this with no added formatting is going to split up the available height or width of the Dialog box (whether you do VBox or HBox respectively) between the buttons. In my example, I create 2 rows with 2 buttons in each row taking up half the row. If I add another button the existing two will shrink to accommodate. But, they have spaces and margins in them.

So, to get around this I add:

Code:
.setStyleSheet("border: 1px solid #fff; height: 100%; width: 100%")
To all of my buttons, and:
Code:
.setSpacing(0)
To both of my HBox's.

The result is 2 buttons per row, and their left and right borders touch. Meaning the button itself is taking exactly 50% of the row. This unfortunately also removes the "button" graphic from the button as well.. so it's just a black box with white borders. Will need to work on formatting it to look pretty. Removing the "border" attribute puts the button graphic back, but it has a fixed height and repeats so it looks very funny .

Unfortunately, the two HBox's still don't touch. There's a pixel or two between the first and second row. There's probably a setting for that too.

I know my example is python, but since it's all QT with the same attributes you should be able to do it in C++ as well.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!
 

The Following User Says Thank You to fatalsaint For This Useful Post:
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#4
Ah, adding the setSpacing ( 0 ) attribute to the parent Vbox in my code made the small space between HBox's go away as well.

So the setSpacing( 0 ) is the primary attribute you're after to make the buttons and HBox's right next to each other... but if you keep the buttons with the default button look they will still appear to have margins and such because of the rounded edges of the corners and the button graphic doesn't fill the box 100%.

If you change the styleSheets of your buttons you get a 100% margin free grid of buttons that dynamically will expand or retract based on what you put into their HBox with them.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!
 

The Following User Says Thank You to fatalsaint For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 13:19.