Hi, i have a QTableWidget and set a cellWidget for one particular cell
The problem is that my widget has a fixed size and want that widget to be centered (horizontally and vertically) within the cell
Any ideas??
Best Regards
Hi, i have a QTableWidget and set a cellWidget for one particular cell
The problem is that my widget has a fixed size and want that widget to be centered (horizontally and vertically) within the cell
Any ideas??
Best Regards
Put it in another widget along with a set of springs that centers it.
I understand how it looks in the Designer But I've asked for some code
I've tried to solve it like this
But it worked the way I didn't expect it to work. The progress bar was centered but it became 3 pixels high not 12Qt Code:
layout.addSpacing(6); layout.addWidget(holder->GetProgressBar()); layout.addSpacing(6); wdg->setLayout(&layout); table->setCellWidget(vectIndex_, 4, wdg);To copy to clipboard, switch view to plain text mode
C++ & AMD forever
Spacing is non-stretchable space. Add stretch instead of spacing.
J-P Nurmi
J-P Nurmi
Here is a screenshot and some code
I can not understand what's the problemQt Code:
movie_->setFileName(":/images/StatusIcons/ico_complete.png"); ic ->setMovie(movie_); layout ->addWidget(ic, 5, Qt::AlignRight); movie_->start(); layout ->addWidget(f); table->setCellWidget(vectIndex_, 3, pL);To copy to clipboard, switch view to plain text mode
C++ & AMD forever
Layouts have margin by default so try:
J-P Nurmi
THRESHE (22nd February 2008)
Damn Layouts are still not so clear to me
I try to use them like this
But I get something like this...Qt Code:
pixmap_.load(":/images/StatusIcons/ico_complete.png"); iconLabel_.setPixmap(pixmap_); layout_.addSpacing(50); layout_.addWidget(&iconLabel_); layout_.addSpacing(5); layout_.addWidget(&textLabel_); layout_.addSpacing(50); layout_.setMargin(0);To copy to clipboard, switch view to plain text mode
C++ & AMD forever
Sorry, from that snippet it's hard to understand which is which. Anyway, it's a very bad idea to allocate widgets on the stack like that. Here are a couple of threads explaining why:
J-P Nurmi
This can be done a lot easier IMO:
Qt Code:
//the tablewidget //some rows and columns tableWidget->setRowCount(3); tableWidget->setColumnCount(3); //first create a new widget //lets say we want a checkbox in the cell // create the layout ON THE HEAP! (else after the function ends, layout is gone) // add the checkbox to the widget layout->addWidget(box); // center align the layout (box ends up in the center horizontally and vertically) layout->setAlignment( Qt::AlignCenter ); // set the layout on the widget, it takes ownership of the layout (don't need to delete it later) wdg->setLayout(layout); // set the widget in the cell tableWidget->setCellWidget(2, 0, wdg);To copy to clipboard, switch view to plain text mode
Thanks. The last example worked for me however the checkbox appears slightly off center in the cell. Any ideas what causes that?
This is in Qt 4.3 on windows XP.
John
Thanks, I will try that.
My first guess for the reason was that there was some space auto allocated for the label that can appear next to the checkbox.
If you have not guessed I am a former MFC programmer...
John
Bookmarks