Qt-interest Archive, May 2007
qtableview -> two issues
Message 1 in thread
Dear Experts,
i'd like to do dialog box with qtableview. First column should contain
just check box (no text, no icon, persistent), the others whatever else.
I have tried to implement this with partial success and I have two
problems:
1) the check box (created as QCheckBox persistent editor) is always left
aligned. I'd like to have it centered. Is there any way how to do it?
2) I'd like to see all cells (horizontally) in dialog. It should be
possible, because in horizontal it contains 5 cells and the total width
of qtableview is ok with respect to the screen width. However when I
create this dialog,
its size is much smaller, thus table view creates horizontal/vertical
scrolbars. I'd like to resize the dialog box automatically according to
the qtableview width. How could I do it?
thanks for any proposals.
david
--
[ signature omitted ]
Message 2 in thread
For (1): In your delegate's ::paint method, set the alignment on the option. For example:
void YourDelegate::paint(
QPainter *painter,
const QStyleOptionViewItem & option,
const QModelIndex & index) const
{
QStyleOptionViewItem myOption = option;
myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
...
}
For the sizing, you can accumulate the width of the cells and then set the minimum width to the total. For example, in the class which instantiates the view:
QTableView *myView = new QTableView(...);
int w = 0;
int count = columnCount();
for (int i = 0; i < count; i++)
w += myView->columnWidth(i);
int maxW =
(w + // total column width
count + // to account for the pixel(s) used in the grid
myView->verticalHeader()->width() +
myView->verticalScrollBar()->width()); // Need room for the vertical scrollbar
myView->setMinimumWidth(maxW);
myView->setMaximumWidth(maxW); // only if you want to make the width fixed
If you want the view to take care of this sizing, then derive from QTableView and do the sizing in the derivation.
HTH,
Susan
----- Original Message ----
From: Dejfson <dejfson@xxxxxxxxx>
To: qt-interest@xxxxxxxxxxxxx
Sent: Wednesday, May 9, 2007 6:22:32 PM
Subject: qtableview -> two issues
Dear Experts,
i'd like to do dialog box with qtableview. First column should contain
just check box (no text, no icon, persistent), the others whatever else.
I have tried to implement this with partial success and I have two
problems:
1) the check box (created as QCheckBox persistent editor) is always left
aligned. I'd like to have it centered. Is there any way how to do it?
2) I'd like to see all cells (horizontally) in dialog. It should be
possible, because in horizontal it contains 5 cells and the total width
of qtableview is ok with respect to the screen width. However when I
create this dialog,
its size is much smaller, thus table view creates horizontal/vertical
scrolbars. I'd like to resize the dialog box automatically according to
the qtableview width. How could I do it?
thanks for any proposals.
david
--
[ signature omitted ]