August 16, 2010

Radical Radical
Lab Rat
5 posts

How do I remove white border around QScrollArea?

 

I’m trying to edit the source of an app called qcomicbook ( http://qcomicbook.linux-projects.net/ ), to remove an annoying 1px white border which persists in full-screen mode.

First I tried changing the background of the main window black, but it had no effect. Here is the newly compiled app against the designer preview:

screenshot

I tried also setting some border and margin style information but the white border remained, so I looked at the cpp source, searched the Qt docs, and made a few simple edits, but they had no effect.

At first I thought this would be a quick cosmetic fix, but now I assume the developer could not find the cause.

He has this inside PageViewBase.cpp:

  1. PageViewBase::PageViewBase(QWidget *parent, int physicalPages, const ViewProperties &props)
  2.     : QScrollArea(parent)
  3.     , m_physicalPages(physicalPages)
  4.     , props(props)
  5.     , smallcursor(NULL)
  6. {
  7.     context_menu = new QMenu(this);
  8.     connect(&this->props, SIGNAL(changed()), this, SLOT(propsChanged()));
  9.     recalculateScrollSpeeds();
  10.  
  11. }

This inside ContinuousPageView.cpp:

  1. ContinuousPageView::ContinuousPageView(QWidget *parent, int physicalPages, const ViewProperties& props)
  2.     : PageViewBase(parent, physicalPages, props)
  3.     , m_firstVisible(-1)
  4.     , m_firstVisibleOffset(0)
  5.     , m_y1pos(NULL)
  6.     , m_y2pos(NULL)
  7. {
  8.     //setFocusPolicy(QWidget::StrongFocus);
  9.  
  10.     QWidget *w = new QWidget(this);
  11. //  w->setColor(QPalette::Background, Qt::black);
  12. // adding above line didn't work
  13. //
  14.     w->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
  15.     m_layout = new QVBoxLayout(w);
  16.     m_layout->setContentsMargins(0, 0, 0, 0);
  17. // changing above line didn't change anything
  18.     m_layout->setSpacing(0);
  19.     m_layout->setAlignment(Qt::AlignCenter);
  20.  
  21.  
  22.     recreatePageWidgets();
  23.     recalculatePageSizes();
  24.  
  25.     setWidget(w);
  26.     setWidgetResizable(true);
  27.  
  28.     setBackground(props.background());
  29.     setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
  30.  
  31.     // track scrollbar range changes to restore its relative position
  32.     connect(verticalScrollBar(), SIGNAL(rangeChanged(int, int)), this, SLOT(scrollbarRangeChanged(int, int)));
  33. }

And this inside ComicMainWindow.cpp:

  1. void ComicMainWindow::setupComicImageView()
  2. {
  3.     const int n = (sink != NULL ? sink->numOfImages() : 0);
  4.     if (view)
  5.     {
  6.         view->disconnect();
  7.         pageLoader->disconnect();
  8.         view->deleteLater();
  9.     }
  10.     const ViewProperties props;
  11.     if (cfg->continuousScrolling())
  12.     {
  13.         view = new ContinuousPageView(this, n, props);
  14.     }
  15.     else
  16.     {
  17.         view = new SimplePageView(this, n, props);
  18.     }
  19.  
  20.     setCentralWidget(view);
  21.     view->setFocus();
  22.  
  23.     reconfigureDisplay();
  24.  
  25.     connect(actionPageTop, SIGNAL(triggered(bool)), view, SLOT(scrollToTop()));
  26.     ...
  27.  
  28. }

Ideas?

4 replies

August 17, 2010

Antonio Di Monaco Antonio Di Monaco
Lab Rat
117 posts

Hi,

QScrollArea is a QFrame descendant. If you set the frame shape to QFrame::NoFrame

setFrameShape(QFrame::NoFrame);

it should disappear … did I understand your point?

Tony.

August 17, 2010

Radical Radical
Lab Rat
5 posts

Tony, thanks, but this did not remove the border.

In Qt, is QFrame the only class which has paints a border?

James

August 17, 2010

Antonio Di Monaco Antonio Di Monaco
Lab Rat
117 posts

Well, I’m not sure that’s the only one. QFrame is a QWidget with a border, so I guess that any widget that’d like to be surrounded by a border, can descend directly from QFrame.

Anyway, it’s really strange that your border does not disappear. If you place a QScrollArea on a QWidget with Qt Designer, you can test it by yourself and it works (are you sure it’s a QScrollArea???)

I can just think about two causes:

a) a particular stylesheet is present, and it draws a border. In this case, you should remove it there.
b) it has a custom paint event. It shouldn’t be so difficult to remove any suspicious drawRect inside that method.

Tony.

August 19, 2010

Radical Radical
Lab Rat
5 posts

Ok, setFrameShape did work actually. The other day I was running make from vi in the wrong dir.

Thanks for the help.

James.

 
  ‹‹ No idea how to manage QWidget      Get filename without extension ››

You must log in to post a reply. Not a member yet? Register here!