У меня есть QToolBar, полный QPushButtons. Поскольку размер окна изменяется, чтобы уменьшить его ширину, ширина панели инструментов уменьшается. Если ширина уменьшается до определенной точки, кнопки начинают исчезать. Я думаю, ситуация понятна.
Бывают определенные ситуации, когда кто-то должен уменьшить ширину окна, поэтому установка минимальной ширины не может быть и речи.
Таким образом, все эти кнопки должны быть доступны независимо от размера окна.
Я думал поместить эти кнопки в раскрывающееся меню, поскольку размер вдовы уменьшается. (Есть ли другой способ?) Я даже не знаю, с чего начать. Если бы кто-нибудь мог сказать мне, как это сделать, или указать мне правильное направление, это было бы здорово.
import sys
from PySide2.QtWidgets import *
from PySide2 import *
class MainWindow(QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.resize(500, 400)
self.setMinimumSize(200, 200)
toolbar = QToolBar()
toolbar.setStyleSheet("QToolBar{"
"background: rgb(60, 60, 60);}")
toolbar.setFixedHeight(30)
a = QPushButton()
a.setFixedSize(25, 25)
a.setText("a")
a.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
b = QPushButton()
b.setFixedSize(25, 25)
b.setText("b")
b.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
c = QPushButton()
c.setFixedSize(25, 25)
c.setText("c")
c.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
d = QPushButton()
d.setFixedSize(25, 25)
d.setText("d")
d.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
e = QPushButton()
e.setFixedSize(25, 25)
e.setText("e")
e.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
f = QPushButton()
f.setFixedSize(25, 25)
f.setText("f")
f.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
g = QPushButton()
g.setFixedSize(25, 25)
g.setText("g")
g.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
h = QPushButton()
h.setFixedSize(25, 25)
h.setText("h")
h.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
i = QPushButton()
i.setFixedSize(25, 25)
i.setText("i")
i.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
j = QPushButton()
j.setFixedSize(25, 25)
j.setText("j")
j.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow}")
k = QPushButton()
k.setFixedSize(25, 25)
k.setText("k")
k.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
l = QPushButton()
l.setFixedSize(25, 25)
l.setText("l")
l.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
m = QPushButton()
m.setFixedSize(25, 25)
m.setText("m")
m.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
n = QPushButton()
n.setFixedSize(25, 25)
n.setText("n")
n.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
o = QPushButton()
o.setFixedSize(25, 25)
o.setText("o")
o.setStyleSheet("QPushButton{"
"color: red;"
"background: yellow;}")
toolbar.addWidget(a)
toolbar.addWidget(b)
toolbar.addWidget(c)
toolbar.addWidget(d)
toolbar.addWidget(e)
toolbar.addWidget(f)
toolbar.addWidget(g)
toolbar.addWidget(h)
toolbar.addWidget(i)
toolbar.addWidget(j)
toolbar.addWidget(k)
toolbar.addWidget(l)
toolbar.addWidget(m)
toolbar.addWidget(n)
toolbar.addWidget(o)
#solution
toolbar.addAction("m", "m")
toolbar.addAction("w", "w")
toolbar.addAction("q", "q")
toolbar.setStyleSheet("QToolBar{background: grey;}"
"QToolButton { background:yellow ;"
"color: red;}")
layout = QVBoxLayout()
layout.addWidget(toolbar)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = MainWindow()
MainWindow.show()
sys.exit(app.exec_())
QToolBar
должен предоставлять некоторые средства доступа к кнопкам, которые становятся невидимыми из-за изменения размера панели инструментов. - person G.M.   schedule 13.05.2020