How to add QSlider to toolbar in mainwindow using pyqt5 in python
up vote
1
down vote
favorite
I'm now using PyQt5 in python to develop a GUI for my program. I have added some QAction to the toolbar, like start, pause and stop icon. However, I don't know how to add a QSlider to the toolbar in my mainwindow. I prefer to add the QSlider to the position which is marked by a red rectangle. Thanks!
python pyqt5
add a comment |
up vote
1
down vote
favorite
I'm now using PyQt5 in python to develop a GUI for my program. I have added some QAction to the toolbar, like start, pause and stop icon. However, I don't know how to add a QSlider to the toolbar in my mainwindow. I prefer to add the QSlider to the position which is marked by a red rectangle. Thanks!
python pyqt5
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm now using PyQt5 in python to develop a GUI for my program. I have added some QAction to the toolbar, like start, pause and stop icon. However, I don't know how to add a QSlider to the toolbar in my mainwindow. I prefer to add the QSlider to the position which is marked by a red rectangle. Thanks!
python pyqt5
I'm now using PyQt5 in python to develop a GUI for my program. I have added some QAction to the toolbar, like start, pause and stop icon. However, I don't know how to add a QSlider to the toolbar in my mainwindow. I prefer to add the QSlider to the position which is marked by a red rectangle. Thanks!
python pyqt5
python pyqt5
asked Nov 11 at 1:28
Jiawei Lu
506
506
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
QToolBar has the addWidget() method that allows you to add widgets:
from PyQt5 import QtCore, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
toolbar = self.addToolBar("toolbar")
toolbar.addAction("start")
toolbar.addAction("pause")
toolbar.addAction("stop")
self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
toolbar.addWidget(self.slider)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
cool! It does work for me. But how can I adjust the size of this slider? I mean it's too long for me. I have tried toolbar.setGeometry function, but it doesn't work. Another question, do you know what does the function toolbar.SetFoucusPolicy do? Thanks for your kind help
– Jiawei Lu
Nov 11 at 5:21
@JiaweiLu if you want to set a fixed width you can usesetFixedWitdh()
, for exampleself.slider.setFixedWidth(100)
, On the other hand, SetFocusPolicy establishes the policy of how the focus gets a widget, for example by pressing the widget, with the TAB key, etc. read doc.qt.io/qt-5/qwidget.html#focusPolicy-prop. On the other hand if my answer does not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
– eyllanesc
Nov 11 at 5:27
A question arises, could we use alignment such astoolbar.addWidget(self.slider, alignment=QtCore.Qt.AlignCenter)
. I do not think so that would work simply. Could thisslider
aligns to left or center?
– Zar Kha
Nov 12 at 9:38
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
QToolBar has the addWidget() method that allows you to add widgets:
from PyQt5 import QtCore, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
toolbar = self.addToolBar("toolbar")
toolbar.addAction("start")
toolbar.addAction("pause")
toolbar.addAction("stop")
self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
toolbar.addWidget(self.slider)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
cool! It does work for me. But how can I adjust the size of this slider? I mean it's too long for me. I have tried toolbar.setGeometry function, but it doesn't work. Another question, do you know what does the function toolbar.SetFoucusPolicy do? Thanks for your kind help
– Jiawei Lu
Nov 11 at 5:21
@JiaweiLu if you want to set a fixed width you can usesetFixedWitdh()
, for exampleself.slider.setFixedWidth(100)
, On the other hand, SetFocusPolicy establishes the policy of how the focus gets a widget, for example by pressing the widget, with the TAB key, etc. read doc.qt.io/qt-5/qwidget.html#focusPolicy-prop. On the other hand if my answer does not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
– eyllanesc
Nov 11 at 5:27
A question arises, could we use alignment such astoolbar.addWidget(self.slider, alignment=QtCore.Qt.AlignCenter)
. I do not think so that would work simply. Could thisslider
aligns to left or center?
– Zar Kha
Nov 12 at 9:38
add a comment |
up vote
1
down vote
accepted
QToolBar has the addWidget() method that allows you to add widgets:
from PyQt5 import QtCore, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
toolbar = self.addToolBar("toolbar")
toolbar.addAction("start")
toolbar.addAction("pause")
toolbar.addAction("stop")
self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
toolbar.addWidget(self.slider)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
cool! It does work for me. But how can I adjust the size of this slider? I mean it's too long for me. I have tried toolbar.setGeometry function, but it doesn't work. Another question, do you know what does the function toolbar.SetFoucusPolicy do? Thanks for your kind help
– Jiawei Lu
Nov 11 at 5:21
@JiaweiLu if you want to set a fixed width you can usesetFixedWitdh()
, for exampleself.slider.setFixedWidth(100)
, On the other hand, SetFocusPolicy establishes the policy of how the focus gets a widget, for example by pressing the widget, with the TAB key, etc. read doc.qt.io/qt-5/qwidget.html#focusPolicy-prop. On the other hand if my answer does not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
– eyllanesc
Nov 11 at 5:27
A question arises, could we use alignment such astoolbar.addWidget(self.slider, alignment=QtCore.Qt.AlignCenter)
. I do not think so that would work simply. Could thisslider
aligns to left or center?
– Zar Kha
Nov 12 at 9:38
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
QToolBar has the addWidget() method that allows you to add widgets:
from PyQt5 import QtCore, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
toolbar = self.addToolBar("toolbar")
toolbar.addAction("start")
toolbar.addAction("pause")
toolbar.addAction("stop")
self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
toolbar.addWidget(self.slider)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
QToolBar has the addWidget() method that allows you to add widgets:
from PyQt5 import QtCore, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
toolbar = self.addToolBar("toolbar")
toolbar.addAction("start")
toolbar.addAction("pause")
toolbar.addAction("stop")
self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
toolbar.addWidget(self.slider)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
answered Nov 11 at 1:41
eyllanesc
69k93052
69k93052
cool! It does work for me. But how can I adjust the size of this slider? I mean it's too long for me. I have tried toolbar.setGeometry function, but it doesn't work. Another question, do you know what does the function toolbar.SetFoucusPolicy do? Thanks for your kind help
– Jiawei Lu
Nov 11 at 5:21
@JiaweiLu if you want to set a fixed width you can usesetFixedWitdh()
, for exampleself.slider.setFixedWidth(100)
, On the other hand, SetFocusPolicy establishes the policy of how the focus gets a widget, for example by pressing the widget, with the TAB key, etc. read doc.qt.io/qt-5/qwidget.html#focusPolicy-prop. On the other hand if my answer does not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
– eyllanesc
Nov 11 at 5:27
A question arises, could we use alignment such astoolbar.addWidget(self.slider, alignment=QtCore.Qt.AlignCenter)
. I do not think so that would work simply. Could thisslider
aligns to left or center?
– Zar Kha
Nov 12 at 9:38
add a comment |
cool! It does work for me. But how can I adjust the size of this slider? I mean it's too long for me. I have tried toolbar.setGeometry function, but it doesn't work. Another question, do you know what does the function toolbar.SetFoucusPolicy do? Thanks for your kind help
– Jiawei Lu
Nov 11 at 5:21
@JiaweiLu if you want to set a fixed width you can usesetFixedWitdh()
, for exampleself.slider.setFixedWidth(100)
, On the other hand, SetFocusPolicy establishes the policy of how the focus gets a widget, for example by pressing the widget, with the TAB key, etc. read doc.qt.io/qt-5/qwidget.html#focusPolicy-prop. On the other hand if my answer does not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
– eyllanesc
Nov 11 at 5:27
A question arises, could we use alignment such astoolbar.addWidget(self.slider, alignment=QtCore.Qt.AlignCenter)
. I do not think so that would work simply. Could thisslider
aligns to left or center?
– Zar Kha
Nov 12 at 9:38
cool! It does work for me. But how can I adjust the size of this slider? I mean it's too long for me. I have tried toolbar.setGeometry function, but it doesn't work. Another question, do you know what does the function toolbar.SetFoucusPolicy do? Thanks for your kind help
– Jiawei Lu
Nov 11 at 5:21
cool! It does work for me. But how can I adjust the size of this slider? I mean it's too long for me. I have tried toolbar.setGeometry function, but it doesn't work. Another question, do you know what does the function toolbar.SetFoucusPolicy do? Thanks for your kind help
– Jiawei Lu
Nov 11 at 5:21
@JiaweiLu if you want to set a fixed width you can use
setFixedWitdh()
, for example self.slider.setFixedWidth(100)
, On the other hand, SetFocusPolicy establishes the policy of how the focus gets a widget, for example by pressing the widget, with the TAB key, etc. read doc.qt.io/qt-5/qwidget.html#focusPolicy-prop. On the other hand if my answer does not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.– eyllanesc
Nov 11 at 5:27
@JiaweiLu if you want to set a fixed width you can use
setFixedWitdh()
, for example self.slider.setFixedWidth(100)
, On the other hand, SetFocusPolicy establishes the policy of how the focus gets a widget, for example by pressing the widget, with the TAB key, etc. read doc.qt.io/qt-5/qwidget.html#focusPolicy-prop. On the other hand if my answer does not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.– eyllanesc
Nov 11 at 5:27
A question arises, could we use alignment such as
toolbar.addWidget(self.slider, alignment=QtCore.Qt.AlignCenter)
. I do not think so that would work simply. Could this slider
aligns to left or center?– Zar Kha
Nov 12 at 9:38
A question arises, could we use alignment such as
toolbar.addWidget(self.slider, alignment=QtCore.Qt.AlignCenter)
. I do not think so that would work simply. Could this slider
aligns to left or center?– Zar Kha
Nov 12 at 9:38
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245066%2fhow-to-add-qslider-to-toolbar-in-mainwindow-using-pyqt5-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown