本文整理汇总了Python中PyQt5.QtWidgets.QWidget.setFixedWidth方法的典型用法代码示例。如果您正苦于以下问题:Python QWidget.setFixedWidth方法的具体用法?Python QWidget.setFixedWidth怎么用?Python QWidget.setFixedWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QWidget
的用法示例。
在下文中一共展示了QWidget.setFixedWidth方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DialogContainer
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setFixedWidth [as 别名]
class DialogContainer(QWidget):
def __init__(self, parent):
QWidget.__init__(self, parent)
self.setStyleSheet("background-color: rgba(30, 30, 30, 0.75);")
self.dialog_widget = QWidget(self)
self.window().resize_event.connect(self.on_main_window_resize)
def paintEvent(self, _):
opt = QStyleOption()
opt.initFrom(self)
painter = QPainter(self)
self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
def close_dialog(self):
try:
self.setParent(None)
self.deleteLater()
except RuntimeError:
pass
def on_main_window_resize(self):
if not self or not self.parentWidget():
return
self.setFixedSize(self.parentWidget().size())
self.dialog_widget.setFixedWidth(self.width() - 100)
self.dialog_widget.move(QPoint(self.geometry().center().x() - self.dialog_widget.geometry().width() / 2,
self.geometry().center().y() - self.dialog_widget.geometry().height() / 2))
示例2: _update
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setFixedWidth [as 别名]
def _update(self):
QWidget.setFixedWidth(self, self._width)
QWidget.setFixedHeight(self, self._height)
QWidget.setSizePolicy(self,
QSizePolicy.Fixed,
QSizePolicy.Fixed)
QWidget.updateGeometry(self)
qp = QPainter()
self._image = self.create_qimage()
for image in self._image:
qp.begin(self._image[0])
#qp.setRenderHint(QPainter.Antialiasing)
self.plot_gantt(
None, qp, self._sim, self._start_date, self._end_date)
qp.end()
示例3: DialogContainer
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setFixedWidth [as 别名]
class DialogContainer(QWidget):
def __init__(self, parent):
super(QWidget, self).__init__(parent)
self.setStyleSheet("background-color: rgba(30, 30, 30, 0.75);")
self.dialog_widget = QWidget(self)
self.window().resize_event.connect(self.on_main_window_resize)
def paintEvent(self, event):
opt = QStyleOption()
opt.initFrom(self)
painter = QPainter(self)
self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
def on_main_window_resize(self):
self.setFixedSize(self.parentWidget().size())
self.dialog_widget.setFixedWidth(self.width() - 100)
self.dialog_widget.move(QPoint(self.geometry().center().x() - self.dialog_widget.geometry().width() / 2,
self.geometry().center().y() - self.dialog_widget.geometry().height() / 2))
示例4: MainTabBar
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setFixedWidth [as 别名]
class MainTabBar(QWidget):
def __init__(self, designWidget, simulateWidget, gencodeWidget, logWidget):
super().__init__()
self.wDesign = designWidget
self.wSimulate = simulateWidget
self.wGenCode = gencodeWidget
self.wLog = logWidget
self.wTabsWidget = QWidget(self)
self.wTabsWidget.setObjectName('wTabsWidget')
self.wTabsWidget.setFixedWidth(200)
self.pbDesign = QPushButton('Design', self.wTabsWidget)
self.pbDesign.setCheckable(True)
self.pbDesign.setIcon(QIcon('images/design.png'))
self.pbDesign.clicked.connect(self._buttonClicked)
self.pbSimulate = QPushButton('Simulate', self.wTabsWidget)
self.pbSimulate.setCheckable(True)
self.pbSimulate.setIcon(QIcon('images/simulate.png'))
self.pbSimulate.clicked.connect(self._buttonClicked)
self.pbGenCode = QPushButton('Generate code', self.wTabsWidget)
self.pbGenCode.setCheckable(True)
self.pbGenCode.setIcon(QIcon('images/codegen.png'))
self.pbGenCode.clicked.connect(self._buttonClicked)
self.pbLog = QPushButton('Log', self.wTabsWidget)
self.pbLog.setObjectName('logbtn')
self.pbLog.setCheckable(True)
self.pbLog.setIcon(QIcon('images/log.png'))
self.pbLog.clicked.connect(self._buttonClicked)
self.vblayout = QVBoxLayout()
self.vblayout.setContentsMargins(0, 0, 0, 0)
self.vblayout.setSpacing(0)
self.vblayout.addWidget(self.pbDesign)
self.vblayout.addWidget(self.pbSimulate)
self.vblayout.addWidget(self.pbGenCode)
self.vblayout.addStretch()
self.vblayout.addWidget(self.pbLog)
self.wTabsWidget.setLayout(self.vblayout)
self.hblayout = QHBoxLayout()
self.hblayout.setContentsMargins(0, 0, 0, 0)
self.hblayout.setSpacing(0)
self.hblayout.addWidget(self.wTabsWidget)
self.hblayout.addWidget(self.wDesign)
self.hblayout.addWidget(self.wSimulate)
self.hblayout.addWidget(self.wGenCode)
self.hblayout.addWidget(self.wLog)
self.setLayout(self.hblayout)
self.setStyleSheet("""
.QWidget#wTabsWidget {
background-color: rgb(50, 50, 54);
border: none;
}
.QPushButton {
color: rgb(194, 194, 195);
text-align: left;
padding-left: 12px;
padding-top: 10px;
padding-bottom: 10px;
padding-right: 10px;
background-color: rgb(50, 50, 54);
border-top: none;
border-bottom: none;
border-right: none;
border-left: 4px solid rgb(50, 50, 54);
qproperty-iconSize: 24px;
}
.QPushButton:hover{
background-color: rgb(74, 73, 80);
border-left: 4px solid rgb(194, 194, 195);
}
.QPushButton:checked {
background-color: rgb(74, 73, 80);
border-left: 4px solid rgb(194, 194, 195);
}
""")
self.swithToTab('design')
self.setGeometry(200, 200, 600, 400)
def setLogCount(self, count):
if count == 0:
self.pbLog.setText('Log')
else:
self.pbLog.setText('Log (' + str(count) + ')')
def setLogState(self, state):
if state == 'error':
#.........这里部分代码省略.........
示例5: add_pip_entry
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setFixedWidth [as 别名]
def add_pip_entry(self, cat_position):
"""
Creates a entry in the ui pipeline with a given position in pipeline.
It also creates the corresponding settings widget.
"""
# create an widget that displays the pip entry in the ui and connect the remove button
pip_main_widget = QWidget()
pip_main_widget.setFixedHeight(70)
pip_main_widget.setFixedWidth(300)
pip_main_layout = QHBoxLayout()
pip_main_widget.setLayout(pip_main_layout)
cat = self.pipeline.executed_cats[cat_position]
alg = cat.active_algorithm
label = alg.get_name()
icon = cat.get_icon()
pixmap = QPixmap(icon)
pixmap_scaled_keeping_aspec = pixmap.scaled(30, 30, QtCore.Qt.KeepAspectRatio)
pixmap_label = QtWidgets.QLabel()
pixmap_label.setPixmap(pixmap_scaled_keeping_aspec)
pip_up_down = QWidget()
pip_up_down.setFixedHeight(70)
pip_up_down_layout = QVBoxLayout()
pip_up_down.setLayout(pip_up_down_layout)
up_btn = QToolButton()
dw_btn = QToolButton()
up_btn.setArrowType(Qt.UpArrow)
up_btn.setFixedHeight(25)
dw_btn.setArrowType(Qt.DownArrow)
dw_btn.setFixedHeight(25)
pip_up_down_layout.addWidget(up_btn)
pip_up_down_layout.addWidget(dw_btn)
string_label = QLabel()
string_label.setText(label)
string_label.setFixedWidth(210)
btn = QtWidgets.QPushButton()
btn.setFixedSize(20, 20)
pixmap_icon = QtGui.QPixmap("./assets/images/delete_x_white.png")
q_icon = QtGui.QIcon(pixmap_icon)
btn.setIcon(q_icon)
pip_main_layout.addWidget(pip_up_down, Qt.AlignVCenter)
pip_main_layout.addWidget(pixmap_label, Qt.AlignVCenter)
pip_main_layout.addWidget(string_label, Qt.AlignLeft)
pip_main_layout.addWidget(btn, Qt.AlignVCenter)
self.pip_widget_vbox_layout.insertWidget(cat_position, pip_main_widget)
index = self.pip_widget_vbox_layout.indexOf(pip_main_widget)
#print(index)
# Create the corresponding settings widget and connect it
settings_main_widget = self.load_settings_widgets_from_pipeline_groupbox(cat_position)
self.settings_collapsable.setTitle("Settings")
self.stackedWidget_Settings.hide()
self.stackedWidget_Settings.insertWidget(cat_position, settings_main_widget)
#print("Read from pipeline entry " + str(cat))
#print("Pipeline length: " + str(len(self.pipeline.executed_cats)) + ".")
def show_settings():
# Set background color while widget is selected. Doesn't work because of theme? *TODO*
p = pip_main_widget.palette()
p.setColor(pip_main_widget.backgroundRole(), Qt.red)
pip_main_widget.setPalette(p)
self.stackedWidget_Settings.show()
self.stackedWidget_Settings.setCurrentIndex(self.pipeline.get_index(cat))
self.settings_collapsable.setTitle(alg.get_name() + " Settings")
self.remove_cat_alg_dropdown()
# Create drop down for cats and algs
self.create_cat_alg_dropdown(self.pipeline.get_index(cat), pip_main_widget, settings_main_widget)
#print(cat)
#print(alg)
self.set_cat_alg_dropdown(cat, alg)
# Connect Button to remove step from pipeline
def delete_button_clicked():
self.remove_pip_entry(pip_main_widget, settings_main_widget, cat)
self.clickable(pixmap_label).connect(show_settings)
self.clickable(string_label).connect(show_settings)
btn.clicked.connect(delete_button_clicked)
return (pip_main_widget, settings_main_widget)
示例6: add_pip_entry_empty
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setFixedWidth [as 别名]
def add_pip_entry_empty(self):
"""
Creates an blank entry in the ui pipeline since the user still needs to specify
a type and an algorithm of the category.
It also creates the corresponding settings widget.
"""
# create an widget that displays the pip entry in the ui and connect the remove button
pip_main_widget = QWidget()
pip_main_widget.setFixedHeight(70)
pip_main_widget.setFixedWidth(300)
pip_main_layout = QHBoxLayout()
pip_main_widget.setLayout(pip_main_layout)
label = "<Click to specify new step>"
icon = None
pixmap = QPixmap(icon)
pixmap_scaled_keeping_aspec = pixmap.scaled(30, 30, QtCore.Qt.KeepAspectRatio)
pixmap_label = QtWidgets.QLabel()
pixmap_label.setPixmap(pixmap_scaled_keeping_aspec)
pip_up_down = QWidget()
pip_up_down.setFixedHeight(70)
pip_up_down_layout = QVBoxLayout()
pip_up_down.setLayout(pip_up_down_layout)
up_btn = QToolButton()
dw_btn = QToolButton()
up_btn.setArrowType(Qt.UpArrow)
up_btn.setFixedHeight(25)
dw_btn.setArrowType(Qt.DownArrow)
dw_btn.setFixedHeight(25)
pip_up_down_layout.addWidget(up_btn)
pip_up_down_layout.addWidget(dw_btn)
string_label = QLabel()
string_label.setText(label)
string_label.setFixedWidth(210)
btn = QtWidgets.QPushButton()
btn.setFixedSize(20, 20)
pixmap_icon = QtGui.QPixmap("./assets/images/delete_x_white.png")
q_icon = QtGui.QIcon(pixmap_icon)
btn.setIcon(q_icon)
pip_main_layout.addWidget(pip_up_down, Qt.AlignVCenter)
pip_main_layout.addWidget(pixmap_label, Qt.AlignVCenter)
pip_main_layout.addWidget(string_label, Qt.AlignLeft)
pip_main_layout.addWidget(btn, Qt.AlignVCenter)
cat_position = len(self.pipeline.executed_cats)
self.pip_widget_vbox_layout.insertWidget(cat_position, pip_main_widget)
index = self.pip_widget_vbox_layout.indexOf(pip_main_widget)
#print(index)
# Create the corresponding empty settings widget and connect it
# settings = self.load_widgets_from_cat_groupbox(cat_position) *TODO* EMPTY
self.settings_collapsable.setTitle("Settings")
self.stackedWidget_Settings.hide()
# Add new step to pipeline
new_category = self.pipeline.new_category(cat_position)
print("Create new entry " + str(new_category))
print("Pipeline length: " + str(len(self.pipeline.executed_cats)) + ".")
settings_main_widget = None
# Connect pipeline entry with corresponding settings widget
def show_settings():
#print("click")
self.stackedWidget_Settings.show()
self.remove_cat_alg_dropdown()
# Create drop down for cats and algs
self.create_cat_alg_dropdown(self.pipeline.get_index(new_category), pip_main_widget, settings_main_widget)
self.stackedWidget_Settings.hide()
# Connect Button to remove step from pipeline
def delete_button_clicked():
self.remove_cat_alg_dropdown()
self.remove_pip_entry(pip_main_widget, settings_main_widget, new_category)
self.clickable(pixmap_label).connect(show_settings)
self.clickable(string_label).connect(show_settings)
btn.clicked.connect(delete_button_clicked)
self.scroll_down_pip()
示例7: _build_gui
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setFixedWidth [as 别名]
def _build_gui(self):
# Storages
buttons = self._buttons
# Unpack dimension data
x, y, width, height = CACHE['dimension']
# If position have not been set before
if x is NotImplemented:
screen = QDesktopWidget().screenGeometry()
x, y = (screen.width() - width) / 2, (screen.height() - height) / 2
# Set window position and dimension
self.setGeometry(x, y, width, height)
self.setFixedWidth(width)
# Create layout for the entire application and zero-out
self.layout = main_layout = QVBoxLayout()
main_layout.setSpacing(0)
main_layout.setContentsMargins(0, 0, 0, 0)
# Create and add scrollable area for streams
self._scroll_area = posts = QScrollArea()
posts.setWidgetResizable(True)
posts.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
posts.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
posts.setFrameShape(QFrame.NoFrame)
# Create a main-stream widget
main_stream = QWidget()
main_stream.setFixedWidth(width)
# TODO: rename self._posts to something meaningful
self._posts = posts_layout = QVBoxLayout()
posts_layout.setSpacing(POST_SPACING_FULL)
posts_layout.setContentsMargins(0, 0, 0, 0)
# HACK: in both scroll arrows the 'padding_left' value is a hack.
# The reason why the arrows are not aligned to the horizontal
# center is unknown as it looks like everything is set up properly
# Add scroll-up icon and text
self._scroll_up = CoubletButtonWidget(icon=CONSTANTS['icon_scroll_up'],
label='SCROLL UP TO REFRESH',
font=CONSTANTS['text_font_generic'],
palette=CONSTANTS['text_color_light'],
order=ICON_AND_LABEL,
orientation=VERTICAL,
spacing=SMALL_PADDING,
padding_top=POST_SPACING_FULL,
padding_left=8)
posts_layout.addWidget(self._scroll_up, alignment=Qt.AlignHCenter)
# Dynamic space
posts_layout.addStretch(0)
# Add scroll-down icon and text
self._scroll_down = CoubletButtonWidget(icon=CONSTANTS['icon_scroll_down'],
label='SCROLL DOWN TO LOAD MORE',
font=CONSTANTS['text_font_generic'],
palette=CONSTANTS['text_color_light'],
order=LABEL_AND_ICON,
orientation=VERTICAL,
spacing=SMALL_PADDING,
padding_bottom=POST_SPACING_FULL,
padding_left=8)
posts_layout.addWidget(self._scroll_down, alignment=Qt.AlignHCenter)
# Set posts' layout to stream, add stream to main layout
main_stream.setLayout(posts_layout)
posts.setWidget(main_stream)
main_layout.addWidget(posts)
# Create menu-bar
menu_bar = QWidget()
menu_bar.setPalette(CONSTANTS['panel_color_darker'])
menu_bar.setAutoFillBackground(True)
# Create layout for menu-bar and zero-out
menu_bar_layout = QVBoxLayout()
menu_bar_layout.setSpacing(0)
menu_bar_layout.setContentsMargins(0, 0, 0, 0)
# Create layout for menu buttons and zero-out
menu_buttons_layout = QHBoxLayout()
menu_buttons_layout.setSpacing(0)
menu_buttons_layout.setContentsMargins(0, 0, 0, 0)
# Add menu-buttons to menu-bar
menu_bar_layout.addSpacing(2*SMALL_PADDING)
menu_bar_layout.addLayout(menu_buttons_layout)
menu_bar_layout.addSpacing(2*SMALL_PADDING)
# Assign layout and add menu-bar to app
menu_bar.setLayout(menu_bar_layout)
main_layout.addWidget(menu_bar)
# Add buttons and spacess to menu-buttons layout
menu_buttons_layout.addSpacing(2*SMALL_PADDING)
# get default double-click interval
for i, menu_item in enumerate(CoubAPI.STREAM_NAMES):
# If not the first item, add
# auto-stretching before it
#.........这里部分代码省略.........