mark28
24th May 2015, 13:06
I have a custom-drawn scrollbar and I'm trying to eliminate some space between a qscrollbar and qabstractscrollarea, this is my code:
MainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Create the scrollarea control
CTE* scrollarea = new CTE(this);
ui->here->addWidget( scrollarea);
}
The scrollarea control
class CTE : public QAbstractScrollArea {
Q_OBJECT
public:
explicit CTE(QWidget *parent = 0);
};
CTE::CTE(QWidget *parent) :
QAbstractScrollArea(parent)
{
scr *m_verticalScrollBar = new scr( );
this->setVerticalScrollBar( m_verticalScrollBar);
this->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
this->setFrameStyle(1);
// Debug code (see image below)
static_cast<QWidget*>(this->verticalScrollBar()->parent()->parent())->setStyleSheet("QWidget { background-color: red; }");
static_cast<QWidget*>(this->verticalScrollBar()->parent())->setStyleSheet("QWidget { background-color: black; }");
}
and the scrollbar
class scr : public QScrollBar
{
public:
scr();
};
scr::scr() :
QScrollBar()
{
}
This is the result and the area I'm trying to eliminate
http://i.stack.imgur.com/1Htjt.png
I can't understand how to get rid of it and especially **who owns that part**. Is it a container that contains my scrollbar and which is a subwidget of MyControl? I have no idea
Can somebody help me out please? I'm using Qt5 on linux and this problem **doesn't show up in Windows with the same exact code**
MainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Create the scrollarea control
CTE* scrollarea = new CTE(this);
ui->here->addWidget( scrollarea);
}
The scrollarea control
class CTE : public QAbstractScrollArea {
Q_OBJECT
public:
explicit CTE(QWidget *parent = 0);
};
CTE::CTE(QWidget *parent) :
QAbstractScrollArea(parent)
{
scr *m_verticalScrollBar = new scr( );
this->setVerticalScrollBar( m_verticalScrollBar);
this->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
this->setFrameStyle(1);
// Debug code (see image below)
static_cast<QWidget*>(this->verticalScrollBar()->parent()->parent())->setStyleSheet("QWidget { background-color: red; }");
static_cast<QWidget*>(this->verticalScrollBar()->parent())->setStyleSheet("QWidget { background-color: black; }");
}
and the scrollbar
class scr : public QScrollBar
{
public:
scr();
};
scr::scr() :
QScrollBar()
{
}
This is the result and the area I'm trying to eliminate
http://i.stack.imgur.com/1Htjt.png
I can't understand how to get rid of it and especially **who owns that part**. Is it a container that contains my scrollbar and which is a subwidget of MyControl? I have no idea
Can somebody help me out please? I'm using Qt5 on linux and this problem **doesn't show up in Windows with the same exact code**