def __init__(self, parent=None): """ Initialize the widget instance. """ # call the base class init super(ElidedLabelDemo, self).__init__(parent) # some text to display in the label start_text = ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque " "non posuere lorem. Donec non lobortis mauris. Morbi risus est, ") # create the label and set the text label = elided_label.ElidedLabel() label.setText(start_text) # a little style to help highlight the label boundaries label.setStyleSheet("background: palette(base);" "padding: 4px;") # ---- add a slider to adjust the width of the label slider = QtGui.QSlider() slider.setOrientation(QtCore.Qt.Horizontal) slider.setMinimum(10) slider.setMaximum(600) slider.setFocusPolicy(QtCore.Qt.NoFocus) # set the initial value slider.valueChanged.connect(label.setFixedWidth) slider.setValue(295) # another label to show instructions in the UI doc = QtGui.QLabel("Move the slider to resize the elided label.") doc.setAlignment(QtCore.Qt.AlignCenter) # lay out the widgets layout = QtGui.QVBoxLayout(self) layout.addStretch() layout.addWidget(label) layout.addSpacing(8) layout.addWidget(slider) layout.addWidget(doc) layout.addStretch()
def _populate_ui(self): """ Build the UI. """ # Button options to change the view model data self._basic_model_button = QtGui.QPushButton("Basic Model", self) self._basic_model_button.setCheckable(True) self._basic_model_button.setFlat(True) self._basic_model_button.clicked.connect(self._toggle_view_model) self._shotgun_model_button = QtGui.QPushButton("ShotGrid Model", self) self._shotgun_model_button.setCheckable(True) self._shotgun_model_button.setFlat(True) self._shotgun_model_button.clicked.connect(self._toggle_view_model) # Button options to change the view mode self._list_view_button = QtGui.QPushButton("List View", self) self._list_view_button.clicked.connect(self._toggle_view_mode) self._list_view_button.setCheckable(True) self._list_view_button.setFlat(True) self._thumbnail_view_button = QtGui.QPushButton("Thumbnail View", self) self._thumbnail_view_button.clicked.connect(self._toggle_view_mode) self._thumbnail_view_button.setCheckable(True) self._thumbnail_view_button.setFlat(True) # Create a slider to dynamically change the view item row height self._size_slider = QtGui.QSlider(QtCore.Qt.Horizontal, self) self._size_slider.setToolTip( "Slider will change row height. This is disabled when the expand checkbox is checked." ) self._size_slider.setMinimum(35) self._size_slider.setMaximum(300) self._size_slider.valueChanged.connect(self._item_size_change) self._size_slider.setValue(75) # Create a checkbox option to set the view to expand to fit all text size_cb = QtGui.QCheckBox("Expand Row to Fit Text", self) size_cb.setToolTip( "Expand the row height to fit all text. Checking this will disable the slider." ) size_cb.stateChanged.connect(self._expand_row_height_to_text_changed) size_cb.setCheckState(QtCore.Qt.Checked) # Set up the top toolbar top_toolbar = QtGui.QWidget(self) top_toolbar_layout = QtGui.QHBoxLayout(self) top_toolbar_layout.addWidget(self._basic_model_button) top_toolbar_layout.addWidget(self._shotgun_model_button) top_toolbar_layout.addStretch() top_toolbar_layout.addWidget(self._list_view_button) top_toolbar_layout.addWidget(self._thumbnail_view_button) top_toolbar.setLayout(top_toolbar_layout) # Set up the bottom toolbar bottom_toolbar = QtGui.QWidget(self) bottom_toolbar_layout = QtGui.QHBoxLayout(self) bottom_toolbar_layout.addWidget(size_cb) bottom_toolbar_layout.addWidget(self._size_slider) bottom_toolbar.setLayout(bottom_toolbar_layout) # Finally layout the main widget layout = QtGui.QVBoxLayout(self) layout.addWidget(top_toolbar) layout.addWidget(self._view) layout.addWidget(bottom_toolbar) self.setLayout(layout) # Start with the displaying the BasicListModel in List mode self._basic_model_button.click() self._list_view_button.click()
def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(1226, 766) self.horizontalLayout_3 = QtGui.QHBoxLayout(Dialog) self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.left_area = QtGui.QVBoxLayout() self.left_area.setSpacing(2) self.left_area.setObjectName("left_area") self.top_toolbar = QtGui.QHBoxLayout() self.top_toolbar.setObjectName("top_toolbar") self.navigation_home = QtGui.QToolButton(Dialog) self.navigation_home.setMinimumSize(QtCore.QSize(40, 40)) self.navigation_home.setMaximumSize(QtCore.QSize(40, 40)) self.navigation_home.setStyleSheet("QToolButton{\n" " border: none;\n" " background-color: none;\n" " background-repeat: no-repeat;\n" " background-position: center center;\n" " background-image: url(:/res/home.png);\n" "}\n" "\n" "QToolButton:hover{\n" "background-image: url(:/res/home_hover.png);\n" "}\n" "\n" "QToolButton:Pressed {\n" "background-image: url(:/res/home_pressed.png);\n" "}\n" "") self.navigation_home.setObjectName("navigation_home") self.top_toolbar.addWidget(self.navigation_home) self.navigation_prev = QtGui.QToolButton(Dialog) self.navigation_prev.setMinimumSize(QtCore.QSize(40, 40)) self.navigation_prev.setMaximumSize(QtCore.QSize(40, 40)) self.navigation_prev.setStyleSheet("QToolButton{\n" " border: none;\n" " background-color: none;\n" " background-repeat: no-repeat;\n" " background-position: center center;\n" " background-image: url(:/res/left_arrow.png);\n" "}\n" "\n" "QToolButton:disabled{\n" " background-image: url(:/res/left_arrow_disabled.png);\n" "}\n" "\n" "QToolButton:hover{\n" "background-image: url(:/res/left_arrow_hover.png);\n" "}\n" "\n" "QToolButton:Pressed {\n" "background-image: url(:/res/left_arrow_pressed.png);\n" "}\n" "") self.navigation_prev.setObjectName("navigation_prev") self.top_toolbar.addWidget(self.navigation_prev) self.navigation_next = QtGui.QToolButton(Dialog) self.navigation_next.setMinimumSize(QtCore.QSize(40, 40)) self.navigation_next.setMaximumSize(QtCore.QSize(40, 40)) self.navigation_next.setStyleSheet("QToolButton{\n" " border: none;\n" " background-color: none;\n" " background-repeat: no-repeat;\n" " background-position: center center;\n" " background-image: url(:/res/right_arrow.png);\n" "}\n" "\n" "QToolButton:disabled{\n" " background-image: url(:/res/right_arrow_disabled.png);\n" "}\n" "\n" "\n" "QToolButton:hover{\n" "background-image: url(:/res/right_arrow_hover.png);\n" "}\n" "\n" "QToolButton:Pressed {\n" "background-image: url(:/res/right_arrow_pressed.png);\n" "}\n" "") self.navigation_next.setObjectName("navigation_next") self.top_toolbar.addWidget(self.navigation_next) self.label = QtGui.QLabel(Dialog) self.label.setText("") self.label.setObjectName("label") self.top_toolbar.addWidget(self.label) self.left_area.addLayout(self.top_toolbar) self.entity_preset_tabs = QtGui.QTabWidget(Dialog) self.entity_preset_tabs.setMaximumSize(QtCore.QSize(300, 16777202)) self.entity_preset_tabs.setUsesScrollButtons(True) self.entity_preset_tabs.setObjectName("entity_preset_tabs") self.left_area.addWidget(self.entity_preset_tabs) self.label_4 = QtGui.QLabel(Dialog) self.label_4.setAlignment(QtCore.Qt.AlignCenter) self.label_4.setObjectName("label_4") self.left_area.addWidget(self.label_4) self.publish_type_list = QtGui.QListView(Dialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Maximum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.publish_type_list.sizePolicy().hasHeightForWidth()) self.publish_type_list.setSizePolicy(sizePolicy) self.publish_type_list.setMinimumSize(QtCore.QSize(100, 100)) self.publish_type_list.setStyleSheet("QListView::item {\n" " border-top: 1px dotted #888888;\n" " padding: 5px;\n" " }") self.publish_type_list.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) self.publish_type_list.setProperty("showDropIndicator", False) self.publish_type_list.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self.publish_type_list.setUniformItemSizes(True) self.publish_type_list.setObjectName("publish_type_list") self.left_area.addWidget(self.publish_type_list) self.horizontalLayout_6 = QtGui.QHBoxLayout() self.horizontalLayout_6.setSpacing(2) self.horizontalLayout_6.setObjectName("horizontalLayout_6") self.check_all = QtGui.QToolButton(Dialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.check_all.sizePolicy().hasHeightForWidth()) self.check_all.setSizePolicy(sizePolicy) self.check_all.setObjectName("check_all") self.horizontalLayout_6.addWidget(self.check_all) self.check_none = QtGui.QToolButton(Dialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.check_none.sizePolicy().hasHeightForWidth()) self.check_none.setSizePolicy(sizePolicy) self.check_none.setObjectName("check_none") self.horizontalLayout_6.addWidget(self.check_none) self.label_3 = QtGui.QLabel(Dialog) self.label_3.setText("") self.label_3.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) self.label_3.setObjectName("label_3") self.horizontalLayout_6.addWidget(self.label_3) self.cog_button = QtGui.QToolButton(Dialog) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/res/gear.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.cog_button.setIcon(icon) self.cog_button.setIconSize(QtCore.QSize(20, 16)) self.cog_button.setPopupMode(QtGui.QToolButton.InstantPopup) self.cog_button.setObjectName("cog_button") self.horizontalLayout_6.addWidget(self.cog_button) self.left_area.addLayout(self.horizontalLayout_6) self.horizontalLayout_3.addLayout(self.left_area) self.middle_area = QtGui.QVBoxLayout() self.middle_area.setObjectName("middle_area") self.horizontalLayout_2 = QtGui.QHBoxLayout() self.horizontalLayout_2.setSpacing(1) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.entity_breadcrumbs = QtGui.QLabel(Dialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.entity_breadcrumbs.sizePolicy().hasHeightForWidth()) self.entity_breadcrumbs.setSizePolicy(sizePolicy) self.entity_breadcrumbs.setMinimumSize(QtCore.QSize(0, 40)) self.entity_breadcrumbs.setText("") self.entity_breadcrumbs.setObjectName("entity_breadcrumbs") self.horizontalLayout_2.addWidget(self.entity_breadcrumbs) spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Minimum) self.horizontalLayout_2.addItem(spacerItem) self.thumbnail_mode = QtGui.QToolButton(Dialog) self.thumbnail_mode.setMinimumSize(QtCore.QSize(0, 26)) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/res/mode_switch_thumb_active.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.thumbnail_mode.setIcon(icon1) self.thumbnail_mode.setCheckable(True) self.thumbnail_mode.setChecked(True) self.thumbnail_mode.setObjectName("thumbnail_mode") self.horizontalLayout_2.addWidget(self.thumbnail_mode) self.list_mode = QtGui.QToolButton(Dialog) self.list_mode.setMinimumSize(QtCore.QSize(0, 26)) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/res/mode_switch_card.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.list_mode.setIcon(icon2) self.list_mode.setCheckable(True) self.list_mode.setObjectName("list_mode") self.horizontalLayout_2.addWidget(self.list_mode) self.label_5 = QtGui.QLabel(Dialog) self.label_5.setMinimumSize(QtCore.QSize(5, 0)) self.label_5.setMaximumSize(QtCore.QSize(5, 16777215)) self.label_5.setText("") self.label_5.setObjectName("label_5") self.horizontalLayout_2.addWidget(self.label_5) self.search_publishes = QtGui.QToolButton(Dialog) self.search_publishes.setMinimumSize(QtCore.QSize(0, 26)) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/res/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.search_publishes.setIcon(icon3) self.search_publishes.setCheckable(True) self.search_publishes.setObjectName("search_publishes") self.horizontalLayout_2.addWidget(self.search_publishes) self.info = QtGui.QToolButton(Dialog) self.info.setMinimumSize(QtCore.QSize(0, 26)) self.info.setObjectName("info") self.horizontalLayout_2.addWidget(self.info) self.middle_area.addLayout(self.horizontalLayout_2) self.publish_frame = QtGui.QFrame(Dialog) self.publish_frame.setObjectName("publish_frame") self.horizontalLayout_7 = QtGui.QHBoxLayout(self.publish_frame) self.horizontalLayout_7.setSpacing(1) self.horizontalLayout_7.setContentsMargins(1, 1, 1, 1) self.horizontalLayout_7.setObjectName("horizontalLayout_7") self.publish_view = QtGui.QListView(self.publish_frame) self.publish_view.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) self.publish_view.setResizeMode(QtGui.QListView.Adjust) self.publish_view.setSpacing(5) self.publish_view.setViewMode(QtGui.QListView.IconMode) self.publish_view.setUniformItemSizes(True) self.publish_view.setObjectName("publish_view") self.horizontalLayout_7.addWidget(self.publish_view) self.middle_area.addWidget(self.publish_frame) self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.show_sub_items = QtGui.QCheckBox(Dialog) self.show_sub_items.setObjectName("show_sub_items") self.horizontalLayout_4.addWidget(self.show_sub_items) spacerItem1 = QtGui.QSpacerItem(128, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_4.addItem(spacerItem1) self.scale_label = QtGui.QLabel(Dialog) self.scale_label.setText("") self.scale_label.setPixmap(QtGui.QPixmap(":/res/search.png")) self.scale_label.setObjectName("scale_label") self.horizontalLayout_4.addWidget(self.scale_label) self.thumb_scale = QtGui.QSlider(Dialog) self.thumb_scale.setMinimumSize(QtCore.QSize(100, 0)) self.thumb_scale.setMaximumSize(QtCore.QSize(100, 16777215)) self.thumb_scale.setStyleSheet("QSlider::groove:horizontal {\n" " /*border: 1px solid #999999; */\n" " height: 2px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */\n" " background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #3F3F3F, stop:1 #545454);\n" " margin: 2px 0;\n" " border-radius: 1px;\n" " }\n" "\n" " QSlider::handle:horizontal {\n" " background: #545454;\n" " border: 1px solid #B6B6B6;\n" " width: 5px;\n" " margin: -2px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */\n" " border-radius: 3px;\n" " }\n" "") self.thumb_scale.setMinimum(70) self.thumb_scale.setMaximum(250) self.thumb_scale.setProperty("value", 70) self.thumb_scale.setSliderPosition(70) self.thumb_scale.setOrientation(QtCore.Qt.Horizontal) self.thumb_scale.setInvertedAppearance(False) self.thumb_scale.setInvertedControls(False) self.thumb_scale.setObjectName("thumb_scale") self.horizontalLayout_4.addWidget(self.thumb_scale) self.middle_area.addLayout(self.horizontalLayout_4) self.horizontalLayout_3.addLayout(self.middle_area) self.details = QtGui.QGroupBox(Dialog) self.details.setMinimumSize(QtCore.QSize(300, 0)) self.details.setMaximumSize(QtCore.QSize(300, 16777215)) self.details.setTitle("") self.details.setObjectName("details") self.verticalLayout_3 = QtGui.QVBoxLayout(self.details) self.verticalLayout_3.setSpacing(2) self.verticalLayout_3.setContentsMargins(4, 4, 4, 4) self.verticalLayout_3.setObjectName("verticalLayout_3") self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem2) self.details_image = QtGui.QLabel(self.details) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.details_image.sizePolicy().hasHeightForWidth()) self.details_image.setSizePolicy(sizePolicy) self.details_image.setMinimumSize(QtCore.QSize(256, 200)) self.details_image.setMaximumSize(QtCore.QSize(256, 200)) self.details_image.setScaledContents(True) self.details_image.setAlignment(QtCore.Qt.AlignCenter) self.details_image.setObjectName("details_image") self.horizontalLayout.addWidget(self.details_image) spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem3) self.verticalLayout_3.addLayout(self.horizontalLayout) self.horizontalLayout_5 = QtGui.QHBoxLayout() self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.details_header = QtGui.QLabel(self.details) self.details_header.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) self.details_header.setWordWrap(True) self.details_header.setObjectName("details_header") self.horizontalLayout_5.addWidget(self.details_header) spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_5.addItem(spacerItem4) self.verticalLayout_4 = QtGui.QVBoxLayout() self.verticalLayout_4.setObjectName("verticalLayout_4") self.detail_playback_btn = QtGui.QToolButton(self.details) self.detail_playback_btn.setMinimumSize(QtCore.QSize(55, 55)) self.detail_playback_btn.setMaximumSize(QtCore.QSize(55, 55)) self.detail_playback_btn.setText("") icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/res/play_icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.detail_playback_btn.setIcon(icon4) self.detail_playback_btn.setIconSize(QtCore.QSize(40, 40)) self.detail_playback_btn.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.detail_playback_btn.setObjectName("detail_playback_btn") self.verticalLayout_4.addWidget(self.detail_playback_btn) self.detail_actions_btn = QtGui.QToolButton(self.details) self.detail_actions_btn.setMinimumSize(QtCore.QSize(55, 0)) self.detail_actions_btn.setMaximumSize(QtCore.QSize(55, 16777215)) self.detail_actions_btn.setPopupMode(QtGui.QToolButton.InstantPopup) self.detail_actions_btn.setToolButtonStyle(QtCore.Qt.ToolButtonTextOnly) self.detail_actions_btn.setObjectName("detail_actions_btn") self.verticalLayout_4.addWidget(self.detail_actions_btn) self.horizontalLayout_5.addLayout(self.verticalLayout_4) self.verticalLayout_3.addLayout(self.horizontalLayout_5) self.version_history_label = QtGui.QLabel(self.details) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Maximum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.version_history_label.sizePolicy().hasHeightForWidth()) self.version_history_label.setSizePolicy(sizePolicy) self.version_history_label.setStyleSheet("QLabel { padding-top: 14px}") self.version_history_label.setAlignment(QtCore.Qt.AlignCenter) self.version_history_label.setWordWrap(True) self.version_history_label.setObjectName("version_history_label") self.verticalLayout_3.addWidget(self.version_history_label) self.history_view = QtGui.QListView(self.details) self.history_view.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel) self.history_view.setHorizontalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel) self.history_view.setUniformItemSizes(True) self.history_view.setObjectName("history_view") self.verticalLayout_3.addWidget(self.history_view) self.horizontalLayout_3.addWidget(self.details) self.horizontalLayout_3.setStretch(0, 1) self.horizontalLayout_3.setStretch(1, 2) self.retranslateUi(Dialog) self.entity_preset_tabs.setCurrentIndex(-1) QtCore.QMetaObject.connectSlotsByName(Dialog) Dialog.setTabOrder(self.navigation_home, self.navigation_prev) Dialog.setTabOrder(self.navigation_prev, self.navigation_next) Dialog.setTabOrder(self.navigation_next, self.publish_type_list) Dialog.setTabOrder(self.publish_type_list, self.show_sub_items) Dialog.setTabOrder(self.show_sub_items, self.thumb_scale) Dialog.setTabOrder(self.thumb_scale, self.history_view)