Why is there a space in QTreeWidget?
-
Hello I have a QTreeWidget. But when I add items to it, there are always spaces before the 1st column and after the last column.
Is there a way to remove them?
-
Hello I have a QTreeWidget. But when I add items to it, there are always spaces before the 1st column and after the last column.
Is there a way to remove them?
@MasterBlade
Can you post how to populate treeWidget ? -
@MasterBlade
Can you post how to populate treeWidget ?@Taz742 said in Why is there a space in QTreeWidget?:
@MasterBlade
Can you post how to populate treeWidget ?void Deck::AMD(int row) { QList<QTreeWidgetItem*> s = ui->DeckList->findItems(ui->CardList->item(row, 0)->text(), Qt::MatchFlag::MatchExactly, 1); if (s.isEmpty()){ QTreeWidgetItem *twi = new QTreeWidgetItem(ui->DeckList); twi->setText(0, "1"); twi->setText(1, ui->CardList->item(row, 0)->text()); twi->setText(2, ui->CardList->item(row, 1)->text()); twi->setTextAlignment(0, Qt::AlignCenter); twi->setTextAlignment(1, Qt::AlignCenter); twi->setTextAlignment(2, Qt::AlignCenter); } else{ uint8_t no = s.constFirst()->text(0).toUInt(); s.constFirst()->setText(0, QString::number(no + 1)); } ui->DeckList->sortByColumn(1, Qt::AscendingOrder); }
-
Hi
You set the text to be center aligned
twi->setTextAlignment(0, Qt::AlignCenter);
so there will be spaces :)
Try with AlignLeft and see. -
Hi
You set the text to be center aligned
twi->setTextAlignment(0, Qt::AlignCenter);
so there will be spaces :)
Try with AlignLeft and see.@mrjj said in Why is there a space in QTreeWidget?:
Hi
You set the text to be center aligned
twi->setTextAlignment(0, Qt::AlignCenter);
so there will be spaces :)
Try with AlignLeft and see.No way. I aligned to the left but still got space.
And there are also spaces at the end of the row.
-
@mrjj said in Why is there a space in QTreeWidget?:
Hi
You set the text to be center aligned
twi->setTextAlignment(0, Qt::AlignCenter);
so there will be spaces :)
Try with AlignLeft and see.No way. I aligned to the left but still got space.
And there are also spaces at the end of the row.
@MasterBlade
Post code again. -
@MasterBlade
Post code again.@Taz742 said in Why is there a space in QTreeWidget?:
@MasterBlade
Post code again.The codes are the same except that I removed the following line.
twi->setTextAlignment(0, Qt::AlignCenter); -
@Taz742 said in Why is there a space in QTreeWidget?:
@MasterBlade
Post code again.The codes are the same except that I removed the following line.
twi->setTextAlignment(0, Qt::AlignCenter);@MasterBlade said in Why is there a space in QTreeWidget?:
twi->setTextAlignment(0, Qt::AlignCenter); twi->setTextAlignment(1, Qt::AlignCenter); twi->setTextAlignment(2, Qt::AlignCenter); }
did you try this?
twi->setTextAlignment(0, Qt::AlignLeft); twi->setTextAlignment(1, Qt::AlignLeft); twi->setTextAlignment(2, Qt::AlignLeft);
-
Hello I have a QTreeWidget. But when I add items to it, there are always spaces before the 1st column and after the last column.
Is there a way to remove them?
@MasterBlade said in Why is there a space in QTreeWidget?:
there are always spaces before the 1st column
Try:
ui->treeWidget->setRootIsDecorated(false); //is true by default, resulting in the space. This space is for a root-decoration image
@MasterBlade said in Why is there a space in QTreeWidget?:
and after the last column
Try:
ui->treeWidget->header()->setStretchLastSection(true);
-
Hello I have a QTreeWidget. But when I add items to it, there are always spaces before the 1st column and after the last column.
Is there a way to remove them?
This post is deleted! -
@MasterBlade said in Why is there a space in QTreeWidget?:
there are always spaces before the 1st column
Try:
ui->treeWidget->setRootIsDecorated(false); //is true by default, resulting in the space. This space is for a root-decoration image
@MasterBlade said in Why is there a space in QTreeWidget?:
and after the last column
Try:
ui->treeWidget->header()->setStretchLastSection(true);
@Diracsbracket said in Why is there a space in QTreeWidget?:
setRootIsDecorated(false);
This Worked!! Many Thanks!!
However I'm still having spaces at the end of the row.
Every time I run this function, the space grows bigger. Is there a way to fix this?
-
@MasterBlade said in Why is there a space in QTreeWidget?:
there are always spaces before the 1st column
Try:
ui->treeWidget->setRootIsDecorated(false); //is true by default, resulting in the space. This space is for a root-decoration image
@MasterBlade said in Why is there a space in QTreeWidget?:
and after the last column
Try:
ui->treeWidget->header()->setStretchLastSection(true);
@Diracsbracket said in Why is there a space in QTreeWidget?:
@MasterBlade said in Why is there a space in QTreeWidget?:
and after the last column
Try:
ui->treeWidget->header()->setStretchLastSection(true);
Actually I already set this in Form View.
-
@MasterBlade said in Why is there a space in QTreeWidget?:
there are always spaces before the 1st column
Try:
ui->treeWidget->setRootIsDecorated(false); //is true by default, resulting in the space. This space is for a root-decoration image
@MasterBlade said in Why is there a space in QTreeWidget?:
and after the last column
Try:
ui->treeWidget->header()->setStretchLastSection(true);
@Diracsbracket said in Why is there a space in QTreeWidget?:
ui->treeWidget->header()->setStretchLastSection(true);
Sorry, this is
true
by default, so wouldn't help in your case.@MasterBlade said in Why is there a space in QTreeWidget?:
However I'm still having spaces at the end of the row.
What value is returned by
qDebug() << ui->treeWidget->columnCount() ;
Somehow, it seems there is an extra empty column in your
QTreeWidget
? -
@Diracsbracket said in Why is there a space in QTreeWidget?:
ui->treeWidget->header()->setStretchLastSection(true);
Sorry, this is
true
by default, so wouldn't help in your case.@MasterBlade said in Why is there a space in QTreeWidget?:
However I'm still having spaces at the end of the row.
What value is returned by
qDebug() << ui->treeWidget->columnCount() ;
Somehow, it seems there is an extra empty column in your
QTreeWidget
?@Diracsbracket said in Why is there a space in QTreeWidget?:
@Diracsbracket said in Why is there a space in QTreeWidget?:
ui->treeWidget->header()->setStretchLastSection(true);
Sorry, this is
true
by default, so wouldn't help in your case.@MasterBlade said in Why is there a space in QTreeWidget?:
However I'm still having spaces at the end of the row.
What value is returned by
qDebug() << ui->treeWidget->columnCount() ;
Somehow, it seems there is an extra empty column in your
QTreeWidget
?I'm sorry but I'm having problem with the debugging. It won't pass.
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
qDebug() << ui->DeckList->columnCount() ;
^Also I added the following. The space is not growing as the function is called. But there is still a space at the end.
ui->DeckList->header()->setStretchLastSection(true);
-
@Diracsbracket said in Why is there a space in QTreeWidget?:
@Diracsbracket said in Why is there a space in QTreeWidget?:
ui->treeWidget->header()->setStretchLastSection(true);
Sorry, this is
true
by default, so wouldn't help in your case.@MasterBlade said in Why is there a space in QTreeWidget?:
However I'm still having spaces at the end of the row.
What value is returned by
qDebug() << ui->treeWidget->columnCount() ;
Somehow, it seems there is an extra empty column in your
QTreeWidget
?I'm sorry but I'm having problem with the debugging. It won't pass.
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
qDebug() << ui->DeckList->columnCount() ;
^Also I added the following. The space is not growing as the function is called. But there is still a space at the end.
ui->DeckList->header()->setStretchLastSection(true);
@MasterBlade said in Why is there a space in QTreeWidget?:
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
You must include
<QDebug>
to useqDebug()
.If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?
-
@MasterBlade said in Why is there a space in QTreeWidget?:
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
You must include
<QDebug>
to useqDebug()
.If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?
@Diracsbracket said in Why is there a space in QTreeWidget?:
@MasterBlade said in Why is there a space in QTreeWidget?:
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
You must include
<QDebug>
to useqDebug()
.If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?
The return value is 3.
I'm using Qt Creator 4.6.1. Based on Qt 5.10.1 (MSVC 2015,32 bit) on Windows 10 x64 -
@MasterBlade said in Why is there a space in QTreeWidget?:
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
You must include
<QDebug>
to useqDebug()
.If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?
@Diracsbracket said in Why is there a space in QTreeWidget?:
@MasterBlade said in Why is there a space in QTreeWidget?:
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
You must include
<QDebug>
to useqDebug()
.If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?
Oh I found the problem. It's on the sorting function.
When I comment this line, everything turns out just fine.
ui->DeckList->sortByColumn(1, Qt::AscendingOrder); -
@Diracsbracket said in Why is there a space in QTreeWidget?:
@MasterBlade said in Why is there a space in QTreeWidget?:
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
You must include
<QDebug>
to useqDebug()
.If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?
Oh I found the problem. It's on the sorting function.
When I comment this line, everything turns out just fine.
ui->DeckList->sortByColumn(1, Qt::AscendingOrder);@MasterBlade said in Why is there a space in QTreeWidget?:
When I comment this line, everything turns out just fine.
Which in itself is weird... sorting should not affect the layout of the treeWidget in that way.
-
@Diracsbracket said in Why is there a space in QTreeWidget?:
@MasterBlade said in Why is there a space in QTreeWidget?:
..\MasterZMDJ\deck.cpp:305:12: error: invalid use of incomplete type 'class QDebug'
You must include
<QDebug>
to useqDebug()
.If the column count is as expected, then it may be Qt bug. Which Qt version are you using? On which platform?
Oh I found the problem. It's on the sorting function.
When I comment this line, everything turns out just fine.
ui->DeckList->sortByColumn(1, Qt::AscendingOrder);@MasterBlade said in Why is there a space in QTreeWidget?:
Oh I found the problem.
Could you put the question as solved then? Cheers!~
-
@MasterBlade said in Why is there a space in QTreeWidget?:
Oh I found the problem.
Could you put the question as solved then? Cheers!~
@Diracsbracket said in Why is there a space in QTreeWidget?:
@MasterBlade said in Why is there a space in QTreeWidget?:
Oh I found the problem.
Could you put the question as solved then? Cheers!~
Sure, thanks for the help!