I am using PySide2 for GUI. I have a "Rename Project" QAction. The function must be like this:

  1. set enable to false if tab name is "*Untitled" or file is unsaved.
  2. set enable to True if file is loaded.
    How to do this?
  3. Whenever switching to tab, these functions should be observed.
commented: a +0

I could be wrong but it sounds like you are asking for code. But let's dive in.

To look at this I read this link: https://wiki.qt.io/Qt_for_Python#What_does_Qt_for_Python_look_like.3F

For item 1 you would craft code to test the tab name then set the object's enable property. Or a flag in the object's handler.

So, is the problem finding the object properties or testing for the condition?

I created a method that would look for tab name like this:

def enable_rename():
    if tab_name != '*Untitled":
        self.rename_action.setEnabled(True)
    else:
        self.rename_action.setEnabled(False)

I put this to my initialization part. But this is not working.

That code doesn't look correct to me. I would have expected to read something about PySide.QtGui.QTabBar.tabText(index).
Documentation appears to be at https://srinikom.github.io/pyside-docs/PySide/QtGui/QTabBar.html

This leads me to think you are just beginning to use Pyside which is all well and good but if you are looking for coders you'll have to put up the project requirements and what the pay for the job is.

Read https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question to cover all the other areas of a good question.

@
QMenuBar menuBar;
QMenu
menuFile;
QAction actionOpen;
QAction
actionClose;

menuBar = new QMenuBar(MainWindow);

menuFile = new QMenu(menuBar);
menuFile->setTitle("File");

actionOpen = new QAction(MainWindow);
actionOpen->setText("Open");

actionClose = new QAction(MainWindow);
actionClose->setText("Close");

menuBar->addAction(menuFile->menuAction());
menuFile->addAction(actionOpen);
menuFile->addAction(actionClose);
@

To disable one of the items or whole "File" menu
@
actionOpen->setEnable(false);
menuFile->setEnable(false);
@

To enable them back
@
actionOpen->setEnable(true);
menuFile->setEnable(true);
@

Hi,

I have few QActions added to a QMenu:
ui->menuView->addAction( pAction1 );
ui->menuView->addAction( pAction2 );
ui->menuView->addAction( pAction3 );

My problem is that I can't disable a particular QAction:
pAction2->setDiasbled( true ); // doesn't do anything

In the documentation it is written: "An action will be disabled when all widgets to which it is added (with QWidget::addAction()) are disabled or not visible."
So why it doesn't work makes sense, but it is not what I want.

How can I do it?

Thanks.