PDA

View Full Version : no horizontal scroll bar in QTableWidget



moskk
17th October 2012, 09:14
hi.
i want to create search results window, so i put QTextBrowsers in QTableWidget's cells using setCellWidget. there is a problem: horizontal scroll bar in QTableWidget is never appears in contrast to the vertical, which is appears when its needed. all scroll bar settings are default.
how can i get this scroll when its needed? and even when i set horizontalScrollBarPolicy in alwaysOn, there is no slider on it even when it should be.
and also how to adjust table's cell size to full browser's text size?
there is some sample code

// ui->tw is a QTableWidget
ui->tw->insertRow(0);
b = new QTextBrowser(ui->tw);
b->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
b->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
b->setWordWrapMode(QTextOption::NoWrap);
b->setHtml(tr("some <b>HTML</b> <i>marked</i> search result <u>that does not fit in table cell without scroll bar</u>"));
ui->tw->setCellWidget(0,0,b);

Ashkan_s
17th October 2012, 10:07
use
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded );

moskk
17th October 2012, 10:19
use
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded );
its not working. Qt::ScrollBarAsNeeded is a default value that used in designer. i tried to set it manualy, thats what i got:8313

Ashkan_s
17th October 2012, 10:36
I think this is because you have only one column (at least it seems so from the picture) and the column (not its contents) is visible so scrolling is not needed.

moskk
17th October 2012, 11:23
I think this is because you have only one column (at least it seems so from the picture) and the column (not its contents) is visible so scrolling is not needed.
thats right. i have added second column and scroll was appeared. thank you very much!;)
but what is the reason of that behavior? am i have to add a fictive column to see the scroll?

Ashkan_s
17th October 2012, 12:07
am i have to add a fictive column to see the scroll? try this: change the scrolling mode to ScrollPerPixel and set a minimum width for the QTableWidget's horizontal header, for example
tb.setHorizontalScrollMode(QAbstractItemView::Scro llPerPixel);
tb.horizontalHeader()->setMinimumWidth(minwidth);
here tb is QTableWidget.

moskk
17th October 2012, 12:24
it works too. thanks!

wysota
17th October 2012, 13:14
Putting text browser instances in QTableWidget is not the right thing to do here. If you need rich text (I'm assuming that's why you put QTextBrowser there), you should implement a rich text delegate for your table widget.

moskk
18th October 2012, 11:51
Putting text browser instances in QTableWidget is not the right thing to do here.
thank you for your participation. i've been googled some about "rich text delegate" and found this (http://stackoverflow.com/questions/1956542/how-to-make-item-view-render-rich-html-text-in-qt) topic. this is what you had in mind?

wysota
18th October 2012, 12:10
Yes, something like that.

marculin
12th April 2017, 15:08
thank you for your participation. i've been googled some about "rich text delegate" and found this (http://stackoverflow.com/questions/1956542/how-to-make-item-view-render-rich-html-text-in-qt) topic. this is what you had in mind?

hi,
then put an entire dialog as QTableWidgetItem in QTable in not correct ??

ty

wysota
13th April 2017, 21:22
No, it's not correct.