Results 1 to 12 of 12

Thread: no horizontal scroll bar in QTableWidget

  1. #1
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default no horizontal scroll bar in QTableWidget

    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
    Qt Code:
    1. // ui->tw is a QTableWidget
    2. ui->tw->insertRow(0);
    3. b = new QTextBrowser(ui->tw);
    4. b->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    5. b->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    6. b->setWordWrapMode(QTextOption::NoWrap);
    7. b->setHtml(tr("some <b>HTML</b> <i>marked</i> search result <u>that does not fit in table cell without scroll bar</u>"));
    8. ui->tw->setCellWidget(0,0,b);
    To copy to clipboard, switch view to plain text mode 
    Last edited by moskk; 17th October 2012 at 11:05. Reason: updated contents

  2. #2
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: no horizontal scroll bar in QTableWidget

    use
    Qt Code:
    1. setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: no horizontal scroll bar in QTableWidget

    Quote Originally Posted by Ashkan_s View Post
    use
    Qt Code:
    1. setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    To copy to clipboard, switch view to plain text mode 
    its not working. Qt::ScrollBarAsNeeded is a default value that used in designer. i tried to set it manualy, thats what i got:no_effect.png

  4. #4
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: no horizontal scroll bar in QTableWidget

    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.
    Last edited by Ashkan_s; 17th October 2012 at 11:59. Reason: spelling corrections

  5. #5
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: no horizontal scroll bar in QTableWidget

    Quote Originally Posted by Ashkan_s View Post
    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?

  6. #6
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: no horizontal scroll bar in QTableWidget

    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
    Qt Code:
    1. tb.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
    2. tb.horizontalHeader()->setMinimumWidth(minwidth);
    To copy to clipboard, switch view to plain text mode 
    here tb is QTableWidget.

  7. #7
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: no horizontal scroll bar in QTableWidget

    it works too. thanks!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: no horizontal scroll bar in QTableWidget

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: no horizontal scroll bar in QTableWidget

    Quote Originally Posted by wysota View Post
    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 topic. this is what you had in mind?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: no horizontal scroll bar in QTableWidget

    Yes, something like that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Apr 2017
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: no horizontal scroll bar in QTableWidget

    Quote Originally Posted by moskk View Post
    thank you for your participation. i've been googled some about "rich text delegate" and found this topic. this is what you had in mind?
    hi,
    then put an entire dialog as QTableWidgetItem in QTable in not correct ??

    ty

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: no horizontal scroll bar in QTableWidget

    No, it's not correct.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 9
    Last Post: 10th October 2012, 13:17
  2. Horizontal scroll bar on QTreeView
    By LynneV in forum Qt Programming
    Replies: 7
    Last Post: 9th November 2010, 22:05
  3. Resizing QTableView to eliminate horizontal scroll bar?
    By russford in forum Qt Programming
    Replies: 7
    Last Post: 18th March 2010, 08:21
  4. Vertical scroll bar, but resizable horizontal content
    By minimoog in forum Qt Programming
    Replies: 0
    Last Post: 14th January 2009, 21:51
  5. ListWidget horizontal scroll.
    By patrick772goh in forum Qt Tools
    Replies: 3
    Last Post: 17th July 2007, 08:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.