How to know when the VerticalScrollBar is showing?
<p>I need to know when the <code>verticalScrollBar</code> of my <code>QTableWidget</code> is being shown.
I am currently using the following instruction:</p>

<p>Header:</p>

<pre><code>#ifndef MYCLASS_H
#define MYCLASS_H

#include &lt;QDebug&gt;
#include &lt;QWidget&gt;
#include &lt;QScrollBar&gt;

namespace Ui {
class MyClass;
}

class MyClass: public QWidget
{
    Q_OBJECT

public:
    explicit MyClass(QWidget *parent = 0);
    ~MyClass();

private:
    void populateTable(QVector&lt;QString&gt; content);

private:
    Ui::MyClass *ui;
};

#endif // MYCLASS_H
</code></pre>

<p>Populate table function:</p>

<pre><code>void MyClass::populateTable(QVector&lt;QString&gt; content)
{
    while( ui-&gt;myTableWidget-&gt;rowCount() &gt; 0 )
    {
        ui-&gt;myTableWidget-&gt;removeRow(0);
    }

    QTableWidgetItem* item;
    for (int row = 0; row &lt; content.length(); ++row)
    {
        ui-&gt;myTableWidget-&gt;insertRow(row);

        item = new QTableWidgetItem( QString::number(row) );
        item-&gt;setTextAlignment(Qt::AlignCenter);
        ui-&gt;myTableWidget-&gt;setItem(row, 0, item);

        item = new QTableWidgetItem( content.at(row) );
        item-&gt;setTextAlignment(Qt::AlignCenter);
        ui-&gt;myTableWidget-&gt;setItem(row, 1, item);
    }

    qDebug() &lt;&lt; "This : " &lt;&lt; this-&gt;isVisible();
    qDebug() &lt;&lt; "QTableWidget : " &lt;&lt; ui-&gt;myTableWidget-&gt;isVisible();
    qDebug() &lt;&lt; "VerticalScrollBar : " &lt;&lt; ui-&gt;myTableWidget-&gt;verticalScrollBar()-&gt;isVisible(); // &lt;-HERE
}
</code></pre>

<p>Output:</p>

<pre><code>// Called from the constructor
This :  false
QTableWidget :  false
VerticalScrollBar :  false

// Called by a button pressed
This :  true
QTableWidget :  true
VerticalScrollBar :  true
This :  true
QTableWidget :  true
VerticalScrollBar :  false
</code></pre>

<p>But it returns a wrong value. When the <strong>ScrollBar</strong> is visible it returns false and when it is not visible it returns true. <strong>Note</strong>: myTableWidget (<code>QTableWidget</code>) is always visible.</p>

<p>Is there any other way that I can do this?</p>

<p>I'm using Qt version 5.3.2</p>