QT: run-time layout rendering and a bit more ;-)
Hi all, in the constructor of one of my widgets I perform the rendering at run-time; Some aspects here I have not grabbed yet, and documentation did not really clear this up to me so far. For the good order, I show my code here:
PHP Code:
The table referenced here has 3 columns: id, name and long_name; I actually want to remove "id" from the view, or rather: let this be the index in the database, rather than the row-number in the view. How can I replace the verticalIndex with the data in column "id" (which is the primary key, and thus unique) in such a way that the table can still be edited? (having issues in this part) |
Why did you wrap C++ code in PHP tags? Use CODE tags instead please.
To get rid of the stretching of the columns, you can use the QTableView::resizeColumnsToContents(). |
I like pretty colors ;-)
As you can see here, it makes code a bit more readable (at least to me): Code:
StatAdminForm::StatAdminForm(QWidget *parent) : |
If I understand your requirements correctly then you might want to look at putting your view in a horizontal layout and then use a horizontal spacer. But you might need to invest sometime in working out how large you want the view to really be. To do that you need to look at the header of the view and then the size hints, something like:
Code:
int widgetSize = view->header()->sectionSizeHint(0) You may want to put that code in a overloaded refresh method of the window. |
I changed the code a bit; upon popular request I'll put it in code-tags, instead of php-tags (so much for pretty colors):
Code:
StatAdminForm::StatAdminForm(QWidget *parent) : |
You probably need to move the widget resize out of the constructor into a different method which you attach to via the geometriesChanged() signal.
If so, the reasoning would be that the view is not populated during the constructor and so the sizehints don't yield meaningful values. Here is an example of something I have done Code:
void StatWordCount::refresh() Code:
connect (ui->treeStatsChapter->header(), SIGNAL(geometriesChanged()),this,SLOT(refresh())); |
interesting, will fiddle around with that;
In the mean time I have been trying and thinking more, and I think I got an error in my thinking: The width of the widget is more than the size of the columns: The widget has 2 borders on the side (duh), each taking a width of 1, hence: int num_borders = 2; The widget is filled with 3 columns, each has a border to the left and to the right, but sharing one if one is already there The maths on that would make num_columns + 1 = amount of column-borders (each with a width of 1) int num_columns = 3; // gives 4 borders |1|2|3| + num_borders for the widget The vertical header also takes space; So I get to this calculation, and this seems to fit perfectly: Code:
hint = view->columnWidth(0) Code:
view->setMinimumWidth(hint); |
All times are GMT -5. The time now is 03:19 PM. |