<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Want to add scroll area only to Layout not entire window]]></title><description><![CDATA[<p dir="auto">I need something like the image attached below.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/de970be7-191e-491e-a473-1b29f6d09df3.jpg" alt="0_1560940750456_Sample.jpg" class=" img-fluid img-markdown" /></p>
<p dir="auto">I am not using any UI, create only inheriting QMainWindow of Qt::FramelessWindowHint.</p>
<p dir="auto">I am confused to achieve this. I want to scroll the scrollbar on mouse move/ scroll/ drug up and down.</p>
<ol>
<li>Need to  fixed the label on top as well as buttons on bottom during the scroll.</li>
<li>Scroll bar should be out side of the QVBoxLayout.</li>
<li>I have coded as:</li>
</ol>
<p dir="auto">setGeometry(0, 0, 240, 320);<br />
QWidget *win = new QWidget(this);<br />
QVBoxLayout mainLayout=new QVBoxLayout(win);<br />
QLabel *titleBar=new QLabel("FORM TITLE");<br />
mainLayout-&gt;addWidget(titleBar);<br />
QVBoxLayout *midLayout=new QVBoxLayout();</p>
<p dir="auto">for(int i=0;i&lt;10;i++{<br />
QCheckBox *chkItems=new QCheckBox("Item :"+str.setNum(i+1));<br />
midLayout-&gt;addWidget(chkItems);<br />
}<br />
mainLayout-&gt;addLayout(midLayout);</p>
<p dir="auto">QVBoxLayout *bottomLayout=new QVBoxLayout();</p>
<p dir="auto">QPushButton *btnSave= new QPushButton(tr("Save"));<br />
QPushButton *btnCacel= new QPushButton(tr("Cancel"));<br />
bottomLayout-&gt;addWidget(btnSave);<br />
bottomLayout-&gt;addWidget(btnCancel);<br />
mainLayout-&gt;addLayout(bottomLayout);</p>
<p dir="auto">QScrollArea *scrollArea=new QScrollArea(this);<br />
scrollArea-&gt;setWidget(win);<br />
scrollArea-&gt;horizontalScrollBar()-&gt;setVisible(false);<br />
setCentralWidget(scrollArea);</p>
<ol start="4">
<li>I could't find any way to add the scroll bar to mainLayout except win (Widget);</li>
</ol>
<p dir="auto">Need help.</p>
]]></description><link>https://forum.qt.io/topic/104096/want-to-add-scroll-area-only-to-layout-not-entire-window</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 04:22:16 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/104096.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 19 Jun 2019 10:56:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Want to add scroll area only to Layout not entire window on Thu, 20 Jun 2019 05:37:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a>  please find my codes:</p>
<p dir="auto">///My globals.h file</p>
<p dir="auto">#ifndef GLOBALS_H<br />
#define GLOBALS_H</p>
<p dir="auto">#define GEOMETRY_X 0<br />
#define GEOMETRY_Y 0<br />
#define GEOMETRY_HEIGHT 320<br />
#define GEOMETRY_WIDTH 240</p>
<p dir="auto">/////My createnew.h file</p>
<p dir="auto">#ifndef CREATENEW_H<br />
#define CREATENEW_H</p>
<p dir="auto">#include &lt;QtGui&gt;<br />
#include &lt;QWidget&gt;<br />
#include &lt;QMainWindow&gt;<br />
class CreateNew : public QMainWindow<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
explicit CreateNew(QWidget *parent = 0);</p>
<p dir="auto">private:<br />
QVBoxLayout *mainLayout;<br />
QVBoxLayout *midLayout;<br />
QHBoxLayout *bottomLayout;<br />
QLabel *title;</p>
<pre><code>QPushButton *btnSave;
QPushButton *btnClose;
</code></pre>
<p dir="auto">signals:</p>
<p dir="auto">private slots:</p>
<pre><code>void on_btnSave_clicked();
void on_btnClose_clicked();
</code></pre>
<p dir="auto">protected:<br />
void keyPressEvent(QKeyEvent *event);<br />
};</p>
<p dir="auto">#endif // CREATENEW_H</p>
<p dir="auto">/////My createnew.cpp file</p>
<p dir="auto">#include "createnew.h"<br />
#include "globals.h"</p>
<p dir="auto">CreateNew::CreateNew(QWidget *parent) :<br />
QMainWindow(parent,Qt::FramelessWindowHint)<br />
{<br />
setGeometry(GEOMETRY_X, GEOMETRY_Y+25, GEOMETRY_WIDTH, GEOMETRY_HEIGHT);<br />
QWidget *win = new QWidget(this);<br />
setCentralWidget(win);</p>
<pre><code>mainLayout=new QVBoxLayout(win);
midLayout=new QVBoxLayout();


midLayout-&gt;setGeometry(QRect(0,50,180,260));
title=new QLabel("Test Form");
midLayout-&gt;addWidget(title);

QString str;
for(int i=0; i&lt;20;i++){
    QCheckBox *qcb=new QCheckBox("Item # :"+str.setNum(i+1));
    qcb-&gt;setStyleSheet("width:80px");
    midLayout-&gt;addWidget(qcb);
}
mainLayout-&gt;addLayout(midLayout);

QScrollArea *scrollArea=new QScrollArea(this);
scrollArea-&gt;setWidget(mainLayout-&gt;widget());
scrollArea-&gt;setStyleSheet("QScrollBar:vertical { width: 5px; }");

bottomLayout=new QHBoxLayout();
btnSave=new QPushButton("Save");
btnClose=new QPushButton("Close");
bottomLayout-&gt;addWidget(btnSave);
bottomLayout-&gt;addWidget(btnClose);
mainLayout-&gt;addLayout(bottomLayout);

connect(btnClose, SIGNAL(clicked()), this, SLOT(on_btnClose_clicked()));
connect(btnSave, SIGNAL(clicked()), this, SLOT(on_btnSave_clicked()));
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void CreateNew::on_btnSave_clicked()<br />
{<br />
this-&gt;close();<br />
}<br />
void CreateNew::on_btnClose_clicked()<br />
{</p>
<p dir="auto">}</p>
<p dir="auto">void CreateNew::keyPressEvent(QKeyEvent *event)<br />
{<br />
if (event-&gt;key() == Qt::Key_Escape ){<br />
this-&gt;close();<br />
}<br />
}</p>
]]></description><link>https://forum.qt.io/post/536338</link><guid isPermaLink="true">https://forum.qt.io/post/536338</guid><dc:creator><![CDATA[Rumzi]]></dc:creator><pubDate>Thu, 20 Jun 2019 05:37:38 GMT</pubDate></item><item><title><![CDATA[Reply to Want to add scroll area only to Layout not entire window on Wed, 19 Jun 2019 12:36:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rumzi">@<bdi>Rumzi</bdi></a></p>
<p dir="auto">Yes you are missing something. Your Widget (win) has no layout.<br />
You set "win" as widget to your ScrollArea, then you set ScrollArea as CentralWidget to your MainWindow.</p>
<pre><code>win-&gt;setLayout(mainLayout);
</code></pre>
<p dir="auto">Should fix it.</p>
]]></description><link>https://forum.qt.io/post/536211</link><guid isPermaLink="true">https://forum.qt.io/post/536211</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Wed, 19 Jun 2019 12:36:33 GMT</pubDate></item><item><title><![CDATA[Reply to Want to add scroll area only to Layout not entire window on Wed, 19 Jun 2019 11:50:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a> I am working with a small device and main purpose to do so Frameless window.</p>
<p dir="auto">I can add scrollbar to the Frameless window but cannot add scrollbar only to the Layout. Somehow I am missing the good point.</p>
]]></description><link>https://forum.qt.io/post/536202</link><guid isPermaLink="true">https://forum.qt.io/post/536202</guid><dc:creator><![CDATA[Rumzi]]></dc:creator><pubDate>Wed, 19 Jun 2019 11:50:37 GMT</pubDate></item><item><title><![CDATA[Reply to Want to add scroll area only to Layout not entire window on Wed, 19 Jun 2019 14:21:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rumzi">@<bdi>Rumzi</bdi></a> said in <a href="/post/536189">Want to add scroll area only to Layout not entire window</a>:</p>
<blockquote>
<p dir="auto">I am not using any UI</p>
</blockquote>
<p dir="auto">Why not?</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rumzi">@<bdi>Rumzi</bdi></a> said in <a href="/post/536189">Want to add scroll area only to Layout not entire window</a>:</p>
<blockquote>
<p dir="auto">I could't find any way to add the scroll bar to mainLayout except win (Widget)</p>
</blockquote>
<p dir="auto">Just adding a random scrollbar to your layout is not possible. <s>You need something like a</s> <a href="https://doc.qt.io/qt-5/qscrollarea.html" target="_blank" rel="noopener noreferrer nofollow ugc"><s>QScrollArea</s></a> <s>and put your widget with your layout inside that area.</s><br />
EDIT: Didnt realized, that you are already using a QScrollWidet :) But you still cant change the scroll + scrollbar behavior per default<br />
What do you mean by</p>
<blockquote>
<p dir="auto">add the scroll bar to mainLayout except win (Widget)</p>
</blockquote>
<p dir="auto">Just place your title label at the top and the buttonbox below outside of the QScrollArea</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rumzi">@<bdi>Rumzi</bdi></a> said in <a href="/post/536189">Want to add scroll area only to Layout not entire window</a>:</p>
<blockquote>
<p dir="auto">I want to scroll the scrollbar on mouse move/ scroll/ drug up and down.</p>
</blockquote>
<p dir="auto">To scroll by moving the mouse to the top / bottom of the widget, you have to implement it on your own by tracking your MouseMovement inside your widget.</p>
<p dir="auto">EDIT_2:</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rumzi">@<bdi>Rumzi</bdi></a> said in <a href="/post/536189">Want to add scroll area only to Layout not entire window</a>:</p>
<blockquote>
<p dir="auto">inheriting QMainWindow of Qt::FramelessWindowHint</p>
</blockquote>
<p dir="auto">Instead of setting the FramelessWindow-flag to your MainWindow, better create a frameless widget / dialog</p>
]]></description><link>https://forum.qt.io/post/536196</link><guid isPermaLink="true">https://forum.qt.io/post/536196</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Wed, 19 Jun 2019 14:21:44 GMT</pubDate></item></channel></rss>