Pablo Flores
Pablo Flores

Reputation: 717

QScrollArea with a QWidget in a QSplitter

I´m making a project for my class, and I need to put a scrollArea in a widget (I choosed a splitter) and I want to push a button and create more scrollArea inside this widget. This is what I´ve done:

I create the button like this:

self.AddCanal = QAction(QIcon(), "Add channel", self, shortcut = "Shift+Ctrl+c", triggered = self.addChannel)

And I put it in a QToolBar().

Then, I create the scrollArea. I put the scrollArea with the Qwidget (in this case I use a QwtPlot) in a QSplitter (splitter1), and then I put a frame and the splitter in another splitter (splitter2). And at last, I put splitter2 and another frame in one last splitter (splitter3). You can see it here:

self.scrollLayout = QFormLayout()
self.canal = QwtPlot()
self.canal.setLayout(self.scrollLayout)
self.scrollArea = QScrollArea()
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.canal)

self.scrollArea = QScrollArea()
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.canal)

splitter2 = QSplitter(Qt.Horizontal)
splitter2.addWidget(self.frame)
splitter2.addWidget(splitter1)

splitter3 = QSplitter(Qt.Vertical)
splitter3.addWidget(splitter2)
splitter3.addWidget(self.frame_3)

I made it like this, because in one frame I will put a tree widget, and in the bottom frame i will put a QtextEdit().

Well, now I need that the button, when click it, creates another scrollArea in the splitter1. And I want to create at minimum 5 extra scrollAreas.

How can I accomplish this?

Upvotes: 0

Views: 811

Answers (1)

Pablo Flores
Pablo Flores

Reputation: 717

I solve it creating a method like this:

def addChannel(self):
    global channelCount
    self.scrollLayout = QFormLayout()

    self.canal = QwtPlot()
    self.canal.setLayout(self.scrollLayout)

    self.scrollArea = QScrollArea()
    self.scrollArea.setWidgetResizable(True)
    self.scrollArea.setWidget(self.canal)

    if channelCount <= 5:           
        self.splitter1.addWidget(self.scrollArea)
        channelCount += 1
        return channelCount

using "channelCount" as a global variable starting it in 1, just because i only want 5.

And i add:

self.addchannel()

at the QMainWindow class

Hope it can help somebody.

Upvotes: 1

Related Questions