PDA

View Full Version : even expansion of combobox



TonyInSoMD
27th December 2018, 12:50
I'm working in Qt Designer. There's more in the window than just these items, but the problem seems to be in the comboboxes so we'll focus on that. The window is a subclass of QWidget, not one of the dialog or main window classes. From here on out I'm going to refer to it as "the window." I've got a window that has a fixed width ListWidget on the left. In the center and right I have a combobox. Think of this as 3 "Columns." The center combobox has a member that is very long, but I want it to start at a shorter width index. The right combobox has a member that is long, but not as long as the center one. How can I set it so that the comboboxes' width are set to a shorter width than their widest member? When I get it set up, I put the window in a grid layout. As soon as I try to resize the window it automatically expands to the width necessary to hold the widest member of each of the 2 combo boxes and I can't make it any narrower. I can set it so that the window and comboxes start at the width I want but setting the minimum width of the comboboxes to the size I want (in this case about 116) and then setting the window size to the minimum I can to just fit all the widgets. I can do that by setting the narrower width as the minimum width of the comboboxes but that seems kind of shaky to me, but that could just be my paranoia. When I expand the window the comboboxes expand at the rate where the center one expands until it fits the widest member and then after it reaches that width then the width of the right combobox starts expanding until its width is the same as the center one and then they both start expanding at the same rate. How can I get it so that they start out at the same width and expand at the same rate when you widen the window? I would attach the ui file to make this easier to understand but my development computer has restricted internet access. One of the sites I can't access is QtCentre for some god forsaken reason. I have no way of transferring files from development computer to my computer with full (basically) internet access. They won't let me use a thumb drive, portable hard drive, burn a CD or anything else to move it over, absolutely nothing. It's ridiculous in this situation where it's QtCentre, but I don't make the rules. There's just no way to do it. I know this was kind of long and I tried to explain it clearly, but if I didn't please let me know and I'll see what I can do to make it easier to understand. Maybe if I beg and plead they'll make an exception and let me use a portable hard drive or something to move it over.

d_stranz
27th December 2018, 23:55
You need a better job, working for someone other than the gummint.

To prevent the comboboxes from expanding, you can set a maximum size. I don't understand why you would think setting a *minimum* width would prevent them from expanding - that just prevents them from getting any smaller than the minimum but has no effect on the maximum width. You can also add a horizontal spacer to a new right column of the grid layout, in the cell next to the combobox. That will push the comboboxes to the left.

Be careful when setting fixed sizes, though. If the default font is changed or the user's PC has font magnification > 100%, then strings may no longer fit into the width you have determined works for *your* PC.

TonyInSoMD
31st December 2018, 20:47
d_stranz, I don't know if you recognize the name, but you've helped me a lot in the past and I thank you for that. Yeah, I went from one gummit contractor to another. This one is not nearly as unreasonable as the last one though. If you tell them you can't reasonably do something, I don't get "Do it anyway." This will probably be one of those cases. I don't have to worry about losing my job just because I said it can't be done within the time constraints. Thank God. Hope you had a good Christmas and if you use the Julian calendar, Happy New Year!

d_stranz
1st January 2019, 00:08
Back in the day, I actually worked for the gummint, a couple of blocks from the White House. One of the things I did while I was there was to rewrite (in my spare time), a big piece of contractor-written software, which like all contractor-written software did what was specified, not what was actually needed. What I did eventually was adopted by the entire agency and earned me a special recognition award.

I knew some of the contractors who had written the original software, and they recognized that what they were writing was hard to use crap, but like you, their hands were tied by their company and by the specifications they had to write against. I was lucky in that I had no such constraints and I could work to make lives better for the people in my own division.

I wasn't cut out to be a gummint employee though, and moved on to better things.