QPushButtons でいっぱいの QToolBar があります。ウィンドウのサイズを変更して幅を縮小すると、ツールバーの幅が縮小されます。幅が特定のポイントを超えて縮小されると、ボタンが消え始めます。状況は理解できると思います。
誰かがウィンドウの幅を縮小しなければならない場合があるため、最小幅を設定することは問題外です。
したがって、基本的に、ウィンドウのサイズに関係なく、これらすべてのボタンにアクセスできる必要があります。
ウィンドウのサイズが縮小されているため、これらのボタンをドロップダウン メニューに配置することを考えていました。(別の方法はありますか?)どこから始めればよいかさえわかりません。誰かがこれを行う方法を教えてくれたり、正しい方向に向けてくれるとしたら、それは素晴らしいことです.
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_())